Skip to content

Commit 68d8055

Browse files
committed
[test] Add make test-dist-esm-plain-esbuild-compat.
1 parent 990b892 commit 68d8055

File tree

6 files changed

+53
-19
lines changed

6 files changed

+53
-19
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ jobs:
3232
- run: npm install
3333
- run: make build
3434
- run: make test-dist-esm-node-import
35+
- run: make test-dist-esm-plain-esbuild-compat
3536
- run: make test-dist-esm-perf
3637
- run: make build-site-twizzle
3738
- run: make build-site-experiments

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# https://github.com/lgarron/Makefile-scripts
33

44
# Note: the first command becomes the default `make` target.
5-
NPM_COMMANDS = build build-esm build-bundle-global build-types build-bin build-sites build-site-twizzle build-site-experiments build-site-typedoc build-search-worker generate-js generate-js-parsers generate-js-svg dev link clean test test-dist-esm-node-import test-dist-esm-parcel test-dist-esm-perf test-dist-experiments test-dist-not-imported-from-src test-import-restrictions test-jest test-tsc format setup initial-setup lint prepack postpublish
5+
NPM_COMMANDS = build build-esm build-bundle-global build-types build-bin build-sites build-site-twizzle build-site-experiments build-site-typedoc build-search-worker generate-js generate-js-parsers generate-js-svg dev link clean test test-dist-esm-node-import test-dist-esm-parcel test-dist-esm-perf test-dist-esm-plain-esbuild-compat test-dist-experiments test-dist-not-imported-from-src test-import-restrictions test-jest test-tsc format setup initial-setup lint prepack postpublish
66

77
.PHONY: $(NPM_COMMANDS)
88
$(NPM_COMMANDS):

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,11 @@
120120
"dev": "npm run initial-setup && node ./script/build/main.js sites dev",
121121
"link": "npm run build && npm link",
122122
"clean": "rm -rf dist .temp coverage src/cubing/search/search-worker-inside-generated* ./alg ./bluetooth ./kpuzzle ./notation ./protocol ./puzzle-geometry ./puzzles ./scramble ./search ./stream ./twisty",
123-
"test": "npm run test-jest && npm run lint && npm run test-import-restrictions && npm run test-tsc # keep test.yml in sync with this",
123+
"test": "npm run test-jest && npm run lint && npm run test-import-restrictions && npm run test-tsc # keep test.yml & build.yml in sync with this",
124124
"test-dist-esm-node-import": "node script/test/dist/esm/node-import/main.mjs",
125125
"test-dist-esm-parcel": "node ./script/test/dist/esm/parcel/main.js",
126126
"test-dist-esm-perf": "node script/test/dist/esm/perf/*.mjs",
127+
"test-dist-esm-plain-esbuild-compat": "node script/test/dist/esm/plain-esbuild-compat/main.js",
127128
"test-dist-experiments": "node ./script/test/dist/experiments/main.js",
128129
"test-dist-not-imported-from-src": "node ./script/test/dist/not-imported-from-src/main.js",
129130
"test-import-restrictions": "node ./script/test/import-restrictions/main.js",
@@ -133,7 +134,7 @@
133134
"setup": "npm install",
134135
"initial-setup": "node ./script/initial-setup/main.js",
135136
"lint": "npx eslint --ext=js,ts src script",
136-
"prepack": "npm run clean && npm run build && npm run test-dist-esm-node-import",
137+
"prepack": "npm run clean && npm run build && npm run test-dist-esm-node-import && npm run test-dist-esm-plain-esbuild-compat",
137138
"postpublish": "echo -e '\n\nConsider updating `cdn.cubing.net` if you have access:\nhttps://github.com/cubing/cdn.cubing.net/blob/main/docs/maintenance.md#updating-cdncubingnet-to-a-new-cubing-version\n'"
138139
},
139140
"keywords": [

script/build/index.js

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { exists, mkdir, readFile, writeFile } from "fs";
1616
import { basename, join } from "path";
1717
import { promisify } from "util";
1818
import { execPromise, spawnPromise } from "../lib/execPromise.js";
19+
import { packageEntryPoints } from "../lib/packages.js";
1920
import { writeSyncUsingTempFile } from "./temp.js";
2021

2122
const PARALLEL = false;
@@ -33,20 +34,6 @@ const ESM_CLASS_PRIVATE_ESBUILD_SUPPORTED = PUBLISH_WITH_PRIVATE_FIELDS
3334
}
3435
: {};
3536

36-
const LIBRARY_ENTRY_POINTS = [
37-
"src/cubing/alg/index.ts",
38-
"src/cubing/bluetooth/index.ts",
39-
"src/cubing/kpuzzle/index.ts",
40-
"src/cubing/notation/index.ts",
41-
"src/cubing/protocol/index.ts",
42-
"src/cubing/puzzle-geometry/index.ts",
43-
"src/cubing/puzzles/index.ts",
44-
"src/cubing/scramble/index.ts",
45-
"src/cubing/stream/index.ts",
46-
"src/cubing/search/index.ts",
47-
"src/cubing/twisty/index.ts",
48-
];
49-
5037
const external = ["three", "comlink"];
5138

5239
function plugins(dev) {
@@ -265,7 +252,7 @@ export const esmTarget = {
265252
buildSelf: async (dev) => {
266253
await esbuild.build({
267254
// TODO: construct entry points based on `exports` (see `staticPackageMetadataTarget`) and add tests.
268-
entryPoints: LIBRARY_ENTRY_POINTS,
255+
entryPoints: packageEntryPoints,
269256
outdir: "dist/esm",
270257
format: "esm",
271258
target: "es2020",
@@ -355,7 +342,7 @@ export const typesTarget = {
355342
}
356343
await spawnPromise("npx", [
357344
"tsup",
358-
...LIBRARY_ENTRY_POINTS,
345+
...packageEntryPoints,
359346
"--dts-only",
360347
"--out-dir",
361348
"dist/types",

script/lib/packages.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { join } from "path";
2+
3+
export const packageNames = [
4+
"alg",
5+
"bluetooth",
6+
"kpuzzle",
7+
"notation",
8+
"protocol",
9+
"puzzle-geometry",
10+
"puzzles",
11+
"scramble",
12+
"stream",
13+
"search",
14+
"twisty",
15+
];
16+
17+
export const packageEntryPoints = packageNames.map((p) =>
18+
join("src/cubing/", p, "/index.ts"),
19+
);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { join } from "path";
2+
import { stdout } from "process";
3+
import { execPromise } from "../../../../lib/execPromise.js";
4+
import { needFolder } from "../../../../lib/need-folder.js";
5+
import { packageNames } from "../../../../lib/packages.js";
6+
7+
const OUT_DIR = "./.temp/plain-esbuild-compat";
8+
9+
needFolder(
10+
new URL("../../../../../dist/esm", import.meta.url).pathname,
11+
"make build-esm",
12+
);
13+
14+
const dist_entries = packageNames
15+
.map((e) => join("dist/esm/", e, "/index.js"))
16+
.join(" ");
17+
console.log(
18+
`npx esbuild --bundle --splitting --outdir="${OUT_DIR}" --format=esm --minify ${dist_entries}`,
19+
);
20+
stdout.write(
21+
"Testing that the ESM build can be transpiled by `esbuild` with default compat settings...",
22+
);
23+
await execPromise(
24+
`npx esbuild --bundle --splitting --outdir="${OUT_DIR}" --format=esm --minify ${dist_entries}`,
25+
);
26+
console.log(" ✅ Success!");

0 commit comments

Comments
 (0)