Skip to content

Commit 20117cd

Browse files
authored
check node engine is provided in package.json (#248)
1 parent 0a5ff75 commit 20117cd

File tree

15 files changed

+293
-183
lines changed

15 files changed

+293
-183
lines changed
Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
---
2-
"bob-the-bundler": patch
2+
'bob-the-bundler': patch
33
---
4+
45
dependencies updates:
5-
- Removed dependency [`@vercel/ncc@^0.36.0` ↗︎](https://www.npmjs.com/package/@vercel/ncc/v/0.36.0) (from `dependencies`)
6-
- Removed dependency [`dependency-graph@^0.11.0` ↗︎](https://www.npmjs.com/package/dependency-graph/v/0.11.0) (from `dependencies`)
7-
- Removed dependency [`tsup@^6.5.0` ↗︎](https://www.npmjs.com/package/tsup/v/6.5.0) (from `dependencies`)
6+
7+
- Removed dependency [`@vercel/ncc@^0.36.0` ↗︎](https://www.npmjs.com/package/@vercel/ncc/v/0.36.0)
8+
(from `dependencies`)
9+
- Removed dependency
10+
[`dependency-graph@^0.11.0` ↗︎](https://www.npmjs.com/package/dependency-graph/v/0.11.0) (from
11+
`dependencies`)
12+
- Removed dependency [`tsup@^6.5.0` ↗︎](https://www.npmjs.com/package/tsup/v/6.5.0) (from
13+
`dependencies`)

.changeset/mean-kings-jump.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'bob-the-bundler': major
3+
---
4+
5+
Require `engines.node` entry with `bob check` command.

src/commands/check.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ const ExportsMapModel = zod.record(
2828
]),
2929
);
3030

31+
const EnginesModel = zod.record(zod.string(), zod.string());
32+
3133
const BinModel = zod.record(zod.string());
3234

3335
export const checkCommand = createCommand<{}, {}>(api => {
@@ -93,6 +95,9 @@ export const checkCommand = createCommand<{}, {}>(api => {
9395
skipExports: new Set<string>(config?.check?.skip ?? []),
9496
includesCommonJS: config?.commonjs ?? true,
9597
});
98+
await checkEngines({
99+
packageJSON: distPackageJSON,
100+
});
96101
} catch (err) {
97102
api.reporter.error(`Integrity check of '${packageJSON.name}' failed.`);
98103
api.reporter.log(err);
@@ -316,6 +321,18 @@ async function checkExportsMapIntegrity(args: {
316321
}
317322
}
318323

324+
async function checkEngines(args: {
325+
packageJSON: {
326+
name: string;
327+
engines: unknown;
328+
};
329+
}) {
330+
const engines = EnginesModel.safeParse(args.packageJSON.engines);
331+
if (engines.success === false || engines.data['node'] === undefined) {
332+
throw new Error('Please specify the node engine version in your package.json.');
333+
}
334+
}
335+
319336
const timeout = `;setTimeout(() => { throw new Error("The Node.js process hangs. There is probably some side-effects. All exports should be free of side effects.") }, 500).unref()`;
320337

321338
function runRequireJSFileCommand(args: { cwd: string; path: string }): ExecaChildProcess {

src/config.ts

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,52 @@
11
import zod from 'zod';
22

33
const BobConfigModel = zod.optional(
4-
zod.union([
5-
zod.literal(false),
6-
zod.object({
7-
commonjs: zod.optional(zod.literal(false), {
8-
description: 'Omit CommonJS output.',
9-
}),
10-
build: zod.union([
11-
zod.literal(false),
12-
zod.optional(
13-
zod.object({
14-
copy: zod.optional(zod.array(zod.string())),
15-
}),
4+
zod.union(
5+
[
6+
zod.literal(false),
7+
zod.object({
8+
commonjs: zod.optional(zod.literal(false), {
9+
description: 'Omit CommonJS output.',
10+
}),
11+
build: zod.union(
12+
[
13+
zod.literal(false),
14+
zod.optional(
15+
zod.object({
16+
copy: zod.optional(zod.array(zod.string()), {
17+
description:
18+
'Specify a list of files that should be copied the the output directory.',
19+
}),
20+
}),
21+
),
22+
],
23+
{
24+
description:
25+
'Build configuration. Set to false for skipping the build of this package.',
26+
},
27+
),
28+
check: zod.optional(
29+
zod.union([
30+
zod.literal(false),
31+
zod.object({
32+
skip: zod.optional(zod.array(zod.string()), {
33+
description:
34+
'Skip certain files from being checked. E.g. modules with side-effects.',
35+
}),
36+
}),
37+
]),
38+
{
39+
description:
40+
'Check whether the built packages comply with the standards. (ESM & CJS compatible and loadable and Node.js engines specified)',
41+
},
1642
),
17-
]),
18-
check: zod.optional(
19-
zod.union([
20-
zod.literal(false),
21-
zod.object({
22-
skip: zod.optional(zod.array(zod.string())),
23-
}),
24-
]),
25-
),
26-
}),
27-
]),
43+
}),
44+
],
45+
{
46+
description:
47+
'Bob configuration. Set this value to false in order to disable running bob on this package.',
48+
},
49+
),
2850
);
2951

3052
export type BobConfig = zod.TypeOf<typeof BobConfigModel>;

test/__fixtures__/simple-esm-only/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{
22
"name": "simple-esm-only",
33
"type": "module",
4+
"engines": {
5+
"node": ">= 14.0.0"
6+
},
47
"main": "dist/esm/index.js",
58
"module": "dist/esm/index.js",
69
"exports": {

test/__fixtures__/simple-monorepo-pnpm/packages/a/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{
22
"name": "a",
33
"type": "module",
4+
"engines": {
5+
"node": ">= 14.0.0"
6+
},
47
"main": "dist/cjs/index.js",
58
"module": "dist/esm/index.js",
69
"exports": {

test/__fixtures__/simple-monorepo-pnpm/packages/b/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{
22
"name": "b",
33
"type": "module",
4+
"engines": {
5+
"node": ">= 14.0.0"
6+
},
47
"bin": {
58
"bbb": "dist/cjs/log-the-world.js"
69
},

test/__fixtures__/simple-monorepo-pnpm/packages/c/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{
22
"name": "c",
3+
"engines": {
4+
"node": ">= 14.0.0"
5+
},
36
"main": "dist/cjs/index.js",
47
"module": "dist/esm/index.js",
58
"exports": {

test/__fixtures__/simple-monorepo/packages/a/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{
22
"name": "a",
33
"type": "module",
4+
"engines": {
5+
"node": ">= 14.0.0"
6+
},
47
"main": "dist/cjs/index.js",
58
"module": "dist/esm/index.js",
69
"exports": {

test/__fixtures__/simple-monorepo/packages/b/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{
22
"name": "b",
33
"type": "module",
4+
"engines": {
5+
"node": ">= 14.0.0"
6+
},
47
"bin": {
58
"bbb": "dist/cjs/log-the-world.js"
69
},

0 commit comments

Comments
 (0)