Skip to content

Commit

Permalink
Merge branch 'main' into v7
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesHenry committed Jun 7, 2023
2 parents 7307520 + 11d8473 commit 40f5226
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 5 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/ci.yml
Expand Up @@ -93,6 +93,9 @@ jobs:
runs-on: windows-latest
env:
LERNA_OS_TYPE: windows
# Set the temp directory to a short dir without username in it otherwise import command specs have a problem because of different paths on windows agents
TEMP: C:\temp
TMP: C:\temp
steps:
- uses: actions/checkout@v3

Expand All @@ -112,12 +115,12 @@ jobs:
# From old maintainer regarding integration tests: "import is NOT TESTED in windows because pain and suffering"
run: |
pids=()
npx nx run integration:integration --ci --maxWorkers=2 --testPathIgnorePatterns=lerna-import.spec.ts &
npx nx run integration:integration --ci --maxWorkers=2 &
pids+=($!)
# Ignored specs currently failing on windows
# TODO: investigate why
npx nx run-many -t test --parallel=3 --ci --maxWorkers=2 --testTimeout=60000 --testPathIgnorePatterns=import-command.spec.ts --testPathIgnorePatterns=save.spec.ts --testPathIgnorePatterns=find-file.spec.ts --testPathIgnorePatterns=chain-class.spec.ts &
npx nx run-many -t test --parallel=3 --ci --maxWorkers=2 --testTimeout=60000 --testPathIgnorePatterns=save.spec.ts --testPathIgnorePatterns=find-file.spec.ts --testPathIgnorePatterns=chain-class.spec.ts &
pids+=($!)
Expand All @@ -138,6 +141,9 @@ jobs:
agent: [1, 2, 3, 4]
env:
LERNA_OS_TYPE: windows
# Set the temp directory to a short dir without containing username, otherwise import command specs have a problem because of different paths on windows agents
TEMP: C:\temp
TMP: C:\temp
steps:
- uses: actions/checkout@v3

Expand Down
8 changes: 8 additions & 0 deletions libs/commands/import/src/index.ts
Expand Up @@ -73,6 +73,14 @@ class ImportCommand extends Command {
const lernaRootRelativeToGitRoot = path.relative(gitRepoRoot, this.project.rootPath);
this.targetDirRelativeToGitRoot = path.join(lernaRootRelativeToGitRoot, targetDir);

//if the target directory is not in the Git root
if (this.targetDirRelativeToGitRoot.startsWith("..")) {
throw new ValidationError(
"ENOTINREPO",
`Project root ${this.project.rootPath} is not a subdirectory of git root ${gitRepoRoot}`
);
}

if (fs.existsSync(path.resolve(this.project.rootPath, targetDir))) {
throw new ValidationError("EEXISTS", `Target directory already exists "${targetDir}"`);
}
Expand Down
14 changes: 14 additions & 0 deletions libs/commands/import/src/lib/import-command.spec.ts
Expand Up @@ -278,6 +278,20 @@ describe("ImportCommand", () => {
await expect(command).rejects.toThrow(`Target directory already exists "${relativePath}"`);
});

it("errors if projectDir is not in repository", async () => {
const [testDir, externalDir] = await initBasicFixtures();
//create a symlinked project
const symlinkedLernaPath = path.join(testDir, "symlink");
const linkedProject = await initFixture("basic");
fs.symlinkSync(linkedProject, symlinkedLernaPath, "dir");

const command = lernaImport(symlinkedLernaPath)(externalDir);

await expect(command).rejects.toThrow(
`Project root ${symlinkedLernaPath} is not a subdirectory of git root`
);
});

it("infers correct target directory given packages glob", async () => {
const [testDir, externalDir] = await initBasicFixtures();
const targetDir = path.join(testDir, "pkg", path.basename(externalDir));
Expand Down
1 change: 1 addition & 0 deletions libs/commands/publish/src/index.ts
Expand Up @@ -989,6 +989,7 @@ class PublishCommand extends Command {
}

this.logger.silly("", err);
this.logger.warn("notice", `Package failed to publish: ${pkg.name}`);
this.logger.error(err.code, (err.body && err.body.error) || err.message);

// avoid dumping logs, this isn't a lerna problem
Expand Down
29 changes: 26 additions & 3 deletions libs/commands/publish/src/lib/publish-from-package.spec.ts
Expand Up @@ -49,9 +49,11 @@ const promptConfirmation = jest.mocked(_promptConfirmation);
const throwIfUncommitted = jest.mocked(_throwIfUncommitted);

// The mock differs from the real thing
const npmPublish = _npmPublish as any;
const writePkg = _writePkg as any;
const output = _output as any;
const npmPublish = _npmPublish as jest.MockedFunction<typeof _npmPublish> & { order: () => string[] };
const writePkg = _writePkg as jest.MockedFunction<typeof _writePkg> & {
updatedManifest: (name: string) => { gitHead?: string };
};
const output = _output as jest.MockedFunction<typeof _output> & { logged: () => string[] };

const initFixture = initFixtureFactory(__dirname);

Expand Down Expand Up @@ -106,6 +108,27 @@ describe("publish from-package", () => {
]);
});

it("logs the name of the package that fails to be published", async () => {
const cwd = await initFixture("independent");

getUnpublishedPackages.mockImplementationOnce((packageGraph) => Array.from(packageGraph.values()));

npmPublish.mockImplementation(async (pkg) => {
if (pkg.name === "package-2") {
throw new Error("some-error");
}
});

try {
await lernaPublish(cwd)("from-package");
} catch {
// ignore error
}

const logMessages = loggingOutput("notice");
expect(logMessages).toContain("Package failed to publish: package-2");
});

it("exits early when all packages are published", async () => {
const cwd = await initFixture("normal");

Expand Down

0 comments on commit 40f5226

Please sign in to comment.