Skip to content

Commit

Permalink
fix: improve rebuild detection (#232)
Browse files Browse the repository at this point in the history
- changed input file detection: default config vs. explicit config (see above)
- changed output detection: default config vs. explicit config (see above)
- fix reading of tsconfig (support comments, inheritance, exclude affects only input)
support custom tsconfig filename
- fix output existence check (handle files)
- support glob as input & output
- remove haveCheckedForRerun from yarn.build.json (no longer necessary)
- mark every non-related project for this build for rerun, when this project was affected by others and therefore needs a build in the future (see above)
- using a checksum based on last modified and size for each file instead of the latest last modified timestamp
  • Loading branch information
zinserjan authored Sep 22, 2022
1 parent 53d85b4 commit e884a41
Show file tree
Hide file tree
Showing 27 changed files with 933 additions and 652 deletions.
157 changes: 79 additions & 78 deletions .pnp.cjs

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
220 changes: 117 additions & 103 deletions .yarn/plugins/@ojkelly/plugin-all.cjs

Large diffs are not rendered by default.

199 changes: 117 additions & 82 deletions .yarn/plugins/@ojkelly/plugin-build.cjs

Large diffs are not rendered by default.

120 changes: 80 additions & 40 deletions .yarn/plugins/@ojkelly/plugin-bundle.cjs

Large diffs are not rendered by default.

199 changes: 117 additions & 82 deletions .yarn/plugins/@ojkelly/plugin-test.cjs

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions packages/examples/words/quitter/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "@internal/quitter",
"version": "1.0.0",
"main": "build/index.js",
"license": "UNLICENSED",
"private": true,
"scripts": {
"build": "tsc --noEmit"
},
"yarn.build": {
"output": null
},
"dependencies": {
"typescript": "^4"
}
}
1 change: 1 addition & 0 deletions packages/examples/words/quitter/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default "quitter";
21 changes: 21 additions & 0 deletions packages/examples/words/quitter/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"extends": "../../../../tsconfig.json",
"compilerOptions": {
"outDir": "build",
"target": "es6",
"module": "commonjs",
"pretty": true,
"baseUrl": ".",
"paths": {
"@src/*": [
"./src/*"
]
}
},
"include": [
"src/**/*"
],
"exclude": [
"src/**/*.spec.ts"
]
}
4 changes: 0 additions & 4 deletions packages/plugins/plugin-all/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"@types/is-ci": "^2.0.0",
"@types/jest": "^26.0.19",
"@types/js-yaml": "^4.0.2",
"@types/micromatch": "^4.0.1",
"@types/yup": "^0.26.12",
"@yarnpkg/builder": "*",
"@yarnpkg/cli": "*",
Expand Down Expand Up @@ -43,11 +42,8 @@
"clipanion": "^3.x",
"date-fns": "^2.12.0",
"esprima": "^4.0.1",
"glob": "^7.2.0",
"glob-promise": "^4.2.2",
"ignore": "^5.1.8",
"is-ci": "^2.0.0",
"micromatch": "^4.0.2",
"p-limit": "^2.3.0",
"p-queue": "^6.3.0",
"slice-ansi": "^4.0.0",
Expand Down
2 changes: 0 additions & 2 deletions packages/plugins/plugin-build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@
"clipanion": "^3.x",
"date-fns": "^2.12.0",
"esprima": "^4.0.1",
"glob": "^7.2.0",
"glob-promise": "^4.2.1",
"ignore": "^5.1.8",
"is-ci": "^2.0.0",
"micromatch": "^4.0.2",
Expand Down
5 changes: 1 addition & 4 deletions packages/plugins/plugin-bundle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"@types/is-ci": "^2.0.0",
"@types/jest": "^26.0.19",
"@types/js-yaml": "^4.0.2",
"@types/micromatch": "^4.0.1",
"@types/yup": "^0.26.12",
"@yarnpkg/builder": "*",
"@yarnpkg/cli": "*",
Expand Down Expand Up @@ -46,11 +45,9 @@
"clipanion": "^3.x",
"date-fns": "^2.12.0",
"esprima": "^4.0.1",
"glob": "^7.2.0",
"glob-promise": "^4.2.1",
"globby": "^11.0.4",
"ignore": "^5.1.8",
"is-ci": "^2.0.0",
"micromatch": "^4.0.2",
"p-limit": "^2.3.0",
"p-queue": "^6.3.0",
"slice-ansi": "^4.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Filename } from "@yarnpkg/fslib";
import glob from "glob-promise";
import globby from "globby";

interface GetAllFilesProps {
cwd: string;
Expand All @@ -9,11 +9,13 @@ export const getAllFiles = async ({
cwd,
}: GetAllFilesProps): Promise<Filename[]> => {
try {
const files = (await glob(`${cwd}/**/*`, { dot: true })) as Filename[];
const files = (await globby(`**/*`, {
dot: true,
cwd: cwd,
absolute: false,
})) as Filename[];

return files
.map((fileName) => fileName.split(`${cwd}/`)[1] ?? "")
.filter(Boolean) as Filename[];
return files;
} catch (_e) {
return [];
}
Expand Down
4 changes: 0 additions & 4 deletions packages/plugins/plugin-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"@types/is-ci": "^2.0.0",
"@types/jest": "^26.0.19",
"@types/js-yaml": "^4.0.2",
"@types/micromatch": "^4.0.1",
"@types/yup": "^0.26.12",
"@yarnpkg/builder": "*",
"@yarnpkg/cli": "*",
Expand Down Expand Up @@ -41,11 +40,8 @@
"clipanion": "^3.x",
"date-fns": "^2.12.0",
"esprima": "^4.0.1",
"glob": "^7.2.0",
"glob-promise": "^4.2.1",
"ignore": "^5.1.8",
"is-ci": "^2.0.0",
"micromatch": "^4.0.2",
"p-limit": "^2.3.0",
"p-queue": "^6.3.0",
"slice-ansi": "^4.0.0",
Expand Down
8 changes: 4 additions & 4 deletions packages/plugins/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"@types/is-ci": "^2.0.0",
"@types/jest": "^26.0.19",
"@types/js-yaml": "^4.0.2",
"@types/micromatch": "^4.0.1",
"@types/node": "^17.0.23",
"@types/object-hash": "^2.2.1",
"@types/yup": "^0.26.12",
"@yarnpkg/builder": "*",
"@yarnpkg/cli": "*",
Expand Down Expand Up @@ -55,11 +55,11 @@
"clipanion": "^3.x",
"date-fns": "^2.12.0",
"esprima": "^4.0.1",
"glob": "^7.2.0",
"glob-promise": "^4.2.2",
"get-tsconfig": "^4.2.0",
"globby": "^11.0.4",
"ignore": "^5.1.8",
"is-ci": "^2.0.0",
"micromatch": "^4.0.2",
"object-hash": "^3.0.0",
"p-limit": "^2.3.0",
"p-queue": "^6.3.0",
"slice-ansi": "^4.0.0",
Expand Down
33 changes: 31 additions & 2 deletions packages/plugins/shared/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,32 @@ const DEFAULT_IGNORE_FILE = ".bundleignore" as Filename;
const isYarnBuildConfiguration = t.isObject({
folders: t.isObject({
input: t.isOneOf([t.isString(), t.isArray(t.isString())]),
output: t.isOneOf([t.isString(), t.isArray(t.isString())]),
output: t.isNullable(t.isOneOf([t.isString(), t.isArray(t.isString())])),
}),
exclude: t.isArray(t.isString()),
bail: t.isBoolean(),
hideYarnBuildBadge: t.isBoolean(),
ignoreFile: t.isString(),
});

const isYarnBuildManifestConfiguration = t.isObject({
input: t.isOptional(t.isOneOf([t.isString(), t.isArray(t.isString())])),
output: t.isOptional(
t.isNullable(t.isOneOf([t.isString(), t.isArray(t.isString())]))
),
tsconfig: t.isOptional(t.isString()),
});

type YarnBuildConfiguration = t.InferType<typeof isYarnBuildConfiguration>;

type YarnBuildManifestConfiguration = t.InferType<
typeof isYarnBuildManifestConfiguration
>;

const DEFAULT_CONFIG: YarnBuildConfiguration = {
folders: {
input: ".",
output: ["build", "node_modules"],
output: null,
},
exclude: [],
bail: true,
Expand Down Expand Up @@ -93,11 +105,28 @@ async function GetPluginConfiguration(
};
}

function getWorkspaceConfiguration(packageJsonManifest: {
[key: string]: any;
}): YarnBuildManifestConfiguration {
const configuration = {
...packageJsonManifest["yarn.build"],
};

if (isYarnBuildManifestConfiguration(configuration)) {
return configuration;
}

return {};
}

export {
isYarnBuildConfiguration,
YarnBuildConfiguration,
GetPluginConfiguration,
GetPartialPluginConfiguration,
DEFAULT_IGNORE_FILE,
DEFAULT_YARN_BUILD_CONFIGRATION_FILENAME,
isYarnBuildManifestConfiguration,
YarnBuildManifestConfiguration,
getWorkspaceConfiguration,
};
Loading

0 comments on commit e884a41

Please sign in to comment.