Skip to content

Commit

Permalink
Merge pull request #4 from sparksuite/polish-and-bug-fixes
Browse files Browse the repository at this point in the history
Polish and bug fixes
  • Loading branch information
WesCossick authored Mar 2, 2021
2 parents 6a53a4c + 79d6c01 commit 5021ef7
Show file tree
Hide file tree
Showing 8 changed files with 609 additions and 20 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"scripts": {
"dev": "yarn install --frozen-lockfile && yarn compile && yarn --cwd ./website install --frozen-lockfile",
"test": "yarn compile && for directory in ./test-projects/*/ ; do (yarn --cwd \"$directory\" test); done",
"test": "yarn compile && node ./dist/index.js",
"lint": "eslint --ext .js,.ts,.jsx,.tsx ./website && prettier --check '**/*.{ts,js,tsx,jsx,json,css,html,yml}'",
"format": "eslint --fix --ext .js,.ts,.jsx,.tsx ./website && prettier --write '**/*.{ts,js,tsx,jsx,json,css,html,yml}'",
"clean": "git clean -X -d --force && find . -type d -empty -delete",
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const finalResult: FinalResult = {
testProjectPaths.map((testProjectPath) => ({
title: path.basename(testProjectPath),
task: async () => {
await execa('yarn', [`remove`, packageFile.name], {
await execa('yarn', [`--mutex`, `file:${configuration.yarnMutexFilePath}`, `remove`, packageFile.name], {
cwd: testProjectPath,
}).catch((error) => {
if (error.toString().includes(`This module isn't specified in a package.json file`)) {
Expand Down Expand Up @@ -95,8 +95,8 @@ const finalResult: FinalResult = {
};

// Trigger each step
await installDependencies(packageFile, testProjectPaths);
await injectRootPackage(packageFile, testProjectPaths);
await installDependencies(configuration, packageFile, testProjectPaths);
await injectRootPackage(configuration, packageFile, testProjectPaths);
await testProjects(testProjectPaths, finalResult);
})()
.catch((error) => {
Expand Down
22 changes: 16 additions & 6 deletions src/steps/inject-root-package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@ import { HandledError, yarnErrorCatcher } from '../utils/errors';
import printHeader from '../utils/print-header';
import { PackageFile } from '../utils/verify';
import tmp from 'tmp';
import { Configuration } from '../utils/configure';

/** Installs dependencies into the root project and test projects */
export default async function injectRootPackage(packageFile: PackageFile, testProjectPaths: string[]) {
export default async function injectRootPackage(
configuration: Configuration,
packageFile: PackageFile,
testProjectPaths: string[]
) {
// Print section header
printHeader(`Injecting ${packageFile.name}`);

Expand Down Expand Up @@ -37,7 +42,7 @@ export default async function injectRootPackage(packageFile: PackageFile, testPr
testProjectPaths.map((testProjectPath) => ({
title: path.basename(testProjectPath),
task: async () => {
await execa('yarn', [`remove`, packageFile.name], {
await execa('yarn', [`--mutex`, `file:${configuration.yarnMutexFilePath}`, `remove`, packageFile.name], {
cwd: testProjectPath,
}).catch((error) => {
if (error.toString().includes(`This module isn't specified in a package.json file`)) {
Expand All @@ -47,9 +52,15 @@ export default async function injectRootPackage(packageFile: PackageFile, testPr
return yarnErrorCatcher(error);
});

await execa('yarn', [`unlink`, packageFile.name], {
await execa('yarn', [`--mutex`, `file:${configuration.yarnMutexFilePath}`, `unlink`, packageFile.name], {
cwd: testProjectPath,
}).catch(yarnErrorCatcher);
}).catch((error) => {
if (error.toString().includes(`No registered package found called`)) {
return;
}

return yarnErrorCatcher(error);
});
},
})),
{
Expand All @@ -65,7 +76,7 @@ export default async function injectRootPackage(packageFile: PackageFile, testPr
testProjectPaths.map((testProjectPath) => ({
title: path.basename(testProjectPath),
task: () =>
execa('yarn', [`add`, `file:${ctx.packagePath}`], {
execa('yarn', [`--mutex`, `file:${configuration.yarnMutexFilePath}`, `add`, `file:${ctx.packagePath}`], {
cwd: testProjectPath,
}).catch(yarnErrorCatcher),
})),
Expand All @@ -79,7 +90,6 @@ export default async function injectRootPackage(packageFile: PackageFile, testPr

// Run the tasks, catching any errors
await tasks.run().catch(() => {
console.log();
throw new HandledError();
});
}
27 changes: 21 additions & 6 deletions src/steps/install-dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@
import execa from 'execa';
import Listr from 'listr';
import path from 'path';
import { Configuration } from '../utils/configure';
import { HandledError, yarnErrorCatcher } from '../utils/errors';
import printHeader from '../utils/print-header';
import { PackageFile } from '../utils/verify';

/** Installs dependencies into the root project and test projects */
export default async function installDependencies(packageFile: PackageFile, testProjectPaths: string[]) {
export default async function installDependencies(
configuration: Configuration,
packageFile: PackageFile,
testProjectPaths: string[]
) {
// Print section header
printHeader('Installing dependencies');

Expand All @@ -16,14 +21,25 @@ export default async function installDependencies(packageFile: PackageFile, test
[
{
title: packageFile.name,
task: () => execa('yarn', [`install`, `--frozen-lockfile`, `--prefer-offline`]).catch(yarnErrorCatcher),
task: () =>
execa('yarn', [
`--mutex`,
`file:${configuration.yarnMutexFilePath}`,
`install`,
`--frozen-lockfile`,
`--prefer-offline`,
]).catch(yarnErrorCatcher),
},
...testProjectPaths.map((testProjectPath) => ({
title: `Project: ${path.basename(testProjectPath)}`,
task: () =>
execa('yarn', [`install`, `--frozen-lockfile`, `--prefer-offline`], {
cwd: testProjectPath,
}).catch(yarnErrorCatcher),
execa(
'yarn',
[`--mutex`, `file:${configuration.yarnMutexFilePath}`, `install`, `--frozen-lockfile`, `--prefer-offline`],
{
cwd: testProjectPath,
}
).catch(yarnErrorCatcher),
})),
],
{
Expand All @@ -34,7 +50,6 @@ export default async function installDependencies(packageFile: PackageFile, test

// Run the tasks, catching any errors
await tasks.run().catch(() => {
console.log();
throw new HandledError();
});
}
1 change: 0 additions & 1 deletion src/steps/test-projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export default async function testProjects(testProjectPaths: string[], finalResu

// Run the tasks, catching any errors
await tasks.run().catch(() => {
console.log();
throw new HandledError();
});
}
5 changes: 5 additions & 0 deletions src/utils/configure.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
// Imports
import tmp from 'tmp';

// Define what configuration looks like
export interface Configuration {
testProjectsDirectory: string;
yarnMutexFilePath: string;
}

/** Construct the configuration object */
export default async function configure(): Promise<Configuration> {
// Return
return {
testProjectsDirectory: 'test-projects',
yarnMutexFilePath: tmp.fileSync().name,
};
}
4 changes: 1 addition & 3 deletions test-projects/todo/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"scripts": {
"pretest": "yarn --frozen-lock-file && RANDOM_STRING=$(LC_ALL=C tr -dc 'A-Za-z0-9' </dev/urandom | head -c 32 ; echo) && yarn remove rugged && yarn --cwd ../../ pack --filename package-$RANDOM_STRING.tgz && yarn add file:./package-$RANDOM_STRING.tgz && rm package-$RANDOM_STRING.tgz",
"test": "node --unhandled-rejections=strict index.test.js",
"posttest": "yarn remove rugged && yarn add link:../.."
"test": "node --unhandled-rejections=strict index.test.js"
},
"dependencies": {
"rugged": "link:../.."
Expand Down
Loading

0 comments on commit 5021ef7

Please sign in to comment.