Skip to content

Commit

Permalink
[build] Move dist/npm to dist/lib
Browse files Browse the repository at this point in the history
This better reflects the purpose of the folder, as it's also appropriate to publish other folders (like `dist/bin`) to `npm`.
  • Loading branch information
lgarron committed Sep 12, 2023
1 parent 90567b7 commit 5937705
Show file tree
Hide file tree
Showing 27 changed files with 122 additions and 119 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ jobs:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: make build-esm
- run: make test-dist-esm-node-import
- run: make test-dist-esm-perf
- run: make test-dist-esm-plain-esbuild-compat
- run: make test-dist-esm-scramble-all-events
- run: make test-dist-esm-vite
- run: make test-dist-esm-build-size
- run: make test-dist-lib-node-import
- run: make test-dist-lib-perf
- run: make test-dist-lib-plain-esbuild-compat
- run: make test-dist-lib-scramble-all-events
- run: make test-dist-lib-vite
- run: make test-dist-lib-build-size
- run: make build-sites
- run: make test-dist-sites-experiments
- run: make clean
Expand Down
52 changes: 26 additions & 26 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -129,34 +129,34 @@ test-build: \
build-site-docs # keep CI.yml in sync with this
.PHONY: test-dist
test-dist: \
test-dist-esm-node-import \
test-dist-esm-scramble-all-events \
test-dist-esm-perf \
test-dist-esm-plain-esbuild-compat \
test-dist-esm-vite \
test-dist-esm-build-size \
test-dist-lib-node-import \
test-dist-lib-scramble-all-events \
test-dist-lib-perf \
test-dist-lib-plain-esbuild-compat \
test-dist-lib-vite \
test-dist-lib-build-size \
test-dist-sites-experiments # keep CI.yml in sync with this
.PHONY: test-dist-esm-node-import
test-dist-esm-node-import: build-esm
${NODE} script/test/dist/npm/cubing/node-import/main.js
.PHONY: test-dist-esm-scramble-all-events
test-dist-esm-scramble-all-events: build-esm
${NODE} script/test/dist/npm/cubing/scramble-all-events/main.js
.PHONY: test-dist-esm-perf
test-dist-esm-perf: build-esm
${NODE} script/test/dist/npm/cubing/perf/*.js
.PHONY: test-dist-esm-plain-esbuild-compat
test-dist-esm-plain-esbuild-compat: build-esm
${NODE} script/test/dist/npm/cubing/plain-esbuild-compat/main.js
.PHONY: test-dist-esm-vite
test-dist-esm-vite: build-esm
${NODE} ./script/test/dist/npm/cubing/vite/main.js
.PHONY: test-dist-esm-build-size
test-dist-esm-build-size: build-esm
${NODE} ./script/test/dist/npm/cubing/build-size/main.js
.PHONY: test-dist-lib-node-import
test-dist-lib-node-import: build-esm
${NODE} script/test/dist/lib/cubing/node-import/main.js
.PHONY: test-dist-lib-scramble-all-events
test-dist-lib-scramble-all-events: build-esm
${NODE} script/test/dist/lib/cubing/scramble-all-events/main.js
.PHONY: test-dist-lib-perf
test-dist-lib-perf: build-esm
${NODE} script/test/dist/lib/cubing/perf/*.js
.PHONY: test-dist-lib-plain-esbuild-compat
test-dist-lib-plain-esbuild-compat: build-esm
${NODE} script/test/dist/lib/cubing/plain-esbuild-compat/main.js
.PHONY: test-dist-lib-vite
test-dist-lib-vite: build-esm
${NODE} ./script/test/dist/lib/cubing/vite/main.js
.PHONY: test-dist-lib-build-size
test-dist-lib-build-size: build-esm
${NODE} ./script/test/dist/lib/cubing/build-size/main.js
.PHONY: test-dist-sites-experiments
test-dist-sites-experiments: build-sites
${NODE} ./script/test/dist/experiments/main.js
${NODE} ./script/test/dist/sites/experiments.cubing.net/main.js
.PHONY: format
format:
${BIOME} format --write ./script ./src
Expand All @@ -172,7 +172,7 @@ lint:
lint-ci:
${BIOME} ci ./script ./src
.PHONY: prepack
prepack: clean build test-dist-esm-node-import test-dist-esm-plain-esbuild-compat
prepack: clean build test-dist-lib-node-import test-dist-lib-plain-esbuild-compat
.PHONY: prepublishOnly
prepublishOnly: test-all
.PHONY: postpublish
Expand Down
60 changes: 30 additions & 30 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,48 +8,48 @@
"repository": "github:cubing/cubing.js",
"exports": {
"./alg": {
"import": "./dist/npm/cubing/alg/index.js",
"types": "./dist/npm/cubing/alg/index.d.ts"
"import": "./dist/lib/cubing/alg/index.js",
"types": "./dist/lib/cubing/alg/index.d.ts"
},
"./bluetooth": {
"import": "./dist/npm/cubing/bluetooth/index.js",
"types": "./dist/npm/cubing/bluetooth/index.d.ts"
"import": "./dist/lib/cubing/bluetooth/index.js",
"types": "./dist/lib/cubing/bluetooth/index.d.ts"
},
"./kpuzzle": {
"import": "./dist/npm/cubing/kpuzzle/index.js",
"types": "./dist/npm/cubing/kpuzzle/index.d.ts"
"import": "./dist/lib/cubing/kpuzzle/index.js",
"types": "./dist/lib/cubing/kpuzzle/index.d.ts"
},
"./notation": {
"import": "./dist/npm/cubing/notation/index.js",
"types": "./dist/npm/cubing/notation/index.d.ts"
"import": "./dist/lib/cubing/notation/index.js",
"types": "./dist/lib/cubing/notation/index.d.ts"
},
"./protocol": {
"import": "./dist/npm/cubing/protocol/index.js",
"types": "./dist/npm/cubing/protocol/index.d.ts"
"import": "./dist/lib/cubing/protocol/index.js",
"types": "./dist/lib/cubing/protocol/index.d.ts"
},
"./puzzle-geometry": {
"import": "./dist/npm/cubing/puzzle-geometry/index.js",
"types": "./dist/npm/cubing/types/puzzle-geometry/index.d.ts"
"import": "./dist/lib/cubing/puzzle-geometry/index.js",
"types": "./dist/lib/cubing/types/puzzle-geometry/index.d.ts"
},
"./puzzles": {
"import": "./dist/npm/cubing/puzzles/index.js",
"types": "./dist/npm/cubing/types-geometry/index.d.ts"
"import": "./dist/lib/cubing/puzzles/index.js",
"types": "./dist/lib/cubing/types-geometry/index.d.ts"
},
"./scramble": {
"import": "./dist/npm/cubing/scramble/index.js",
"types": "./dist/npm/cubing/scramble/index.d.ts"
"import": "./dist/lib/cubing/scramble/index.js",
"types": "./dist/lib/cubing/scramble/index.d.ts"
},
"./search": {
"import": "./dist/npm/cubing/search/index.js",
"types": "./dist/npm/cubing/search/index.d.ts"
"import": "./dist/lib/cubing/search/index.js",
"types": "./dist/lib/cubing/search/index.d.ts"
},
"./stream": {
"import": "./dist/npm/cubing/stream/index.js",
"types": "./dist/npm/cubing/stream/index.d.ts"
"import": "./dist/lib/cubing/stream/index.js",
"types": "./dist/lib/cubing/stream/index.d.ts"
},
"./twisty": {
"import": "./dist/npm/cubing/twisty/index.js",
"types": "./dist/npm/cubing/twisty/index.d.ts"
"import": "./dist/lib/cubing/twisty/index.js",
"types": "./dist/lib/cubing/twisty/index.d.ts"
}
},
"dependencies": {
Expand Down Expand Up @@ -98,8 +98,8 @@
"/README.md",
"/package.json",
"/package-lock.json",
"/dist/npm/cubing/**/*",
"/dist/npm/cubing/**/*",
"/dist/lib/cubing/**/*",
"/dist/lib/cubing/**/*",
"/*/package.json",
"/*/index.d.ts"
],
Expand Down Expand Up @@ -134,12 +134,12 @@
"fix-src-scripts-consistency": "make fix-src-scripts-consistency",
"test-build": "make test-build",
"test-dist": "make test-dist",
"test-dist-esm-node-import": "make test-dist-esm-node-import",
"test-dist-esm-scramble-all-events": "make test-dist-esm-scramble-all-events",
"test-dist-esm-perf": "make test-dist-esm-perf",
"test-dist-esm-plain-esbuild-compat": "make test-dist-esm-plain-esbuild-compat",
"test-dist-esm-vite": "make test-dist-esm-vite",
"test-dist-esm-build-size": "make test-dist-esm-build-size",
"test-dist-lib-node-import": "make test-dist-lib-node-import",
"test-dist-lib-scramble-all-events": "make test-dist-lib-scramble-all-events",
"test-dist-lib-perf": "make test-dist-lib-perf",
"test-dist-lib-plain-esbuild-compat": "make test-dist-lib-plain-esbuild-compat",
"test-dist-lib-vite": "make test-dist-lib-vite",
"test-dist-lib-build-size": "make test-dist-lib-build-size",
"test-dist-sites-experiments": "make test-dist-sites-experiments",
"format": "make format",
"setup": "make setup",
Expand Down
8 changes: 4 additions & 4 deletions script/build/targets.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export const esmTarget = {
const build = await esbuild.build({
// TODO: construct entry points based on `exports` and add tests.
entryPoints: packageEntryPointsWithSearchWorkerEntry,
outdir: "dist/npm/cubing",
outdir: "dist/lib/cubing",
format: "esm",
target: "es2020",
bundle: true,
Expand Down Expand Up @@ -213,7 +213,7 @@ export const twizzleTarget = {
await barelyServe(siteOptions("sites/alpha.twizzle.net", dev));
if (!dev) {
// TODO: Include this in the custom build process.
await writeVersionJSON("dist/sites/alpha.twizzle.net");
await writeVersionJSON("dist([-/])sites/alpha.twizzle.net");
}
},
};
Expand All @@ -229,7 +229,7 @@ export const experimentsTarget = {

if (!dev) {
// TODO: Include this in the custom build process.
await writeVersionJSON("dist/sites/alpha.twizzle.net");
await writeVersionJSON("dist([-/])sites/alpha.twizzle.net");
}
},
};
Expand All @@ -248,7 +248,7 @@ export const typesTarget = {
...packageEntryPoints,
"--dts-only",
"--out-dir",
"dist/npm/cubing",
"dist/lib/cubing",
]);
},
};
Expand Down
2 changes: 1 addition & 1 deletion script/deploy/experiments.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const experimentsSFTPPath =
const experimentsURL = "https://experiments.cubing.net/cubing.js/";

await rsync(
"./dist/sites/experiments.cubing.net/cubing.js/",
"./dist([-/])sites/experiments.cubing.net/cubing.js/",
experimentsSFTPPath,
);
console.log(`Done deploying. Go to: ${experimentsURL}`);
2 changes: 1 addition & 1 deletion script/deploy/twizzle.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function ensureTrailingSlash(path) {
}

await rsync(
"./dist/sites/alpha.twizzle.net/",
"./dist([-/])sites/alpha.twizzle.net/",
`${twizzleSSHServer}:${twizzleSFTPUploadPath}/`,
{ exclude: [".DS_Store", ".git"], delete: true },
);
Expand Down
2 changes: 1 addition & 1 deletion script/deploy/typedoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ const typedocSFTPPath =
"[email protected]:~/experiments.cubing.net/cubing.js-typedoc/";
const typedocURL = "https://experiments.cubing.net/cubing.js-typedoc/";

await rsync("./dist/sites/typedoc/", typedocSFTPPath);
await rsync("./dist([-/])sites/typedoc/", typedocSFTPPath);
console.log(`Done deploying. Go to: ${typedocURL}`);
2 changes: 1 addition & 1 deletion script/lib/experiments-server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { createServer } from "node:http";
import { extname, join } from "node:path";
import { needFolder } from "../need-folder.js";

const DIST_SITES_ROOT = "../../../dist/sites/";
const DIST_SITES_ROOT = "../../../dist([-/])sites/";

const DIST_SITES_ROOT_EXPANDED = new URL(DIST_SITES_ROOT, import.meta.url)
.pathname;
Expand Down
11 changes: 0 additions & 11 deletions script/test/dist/cubing/build-size/src/total.js

This file was deleted.

8 changes: 0 additions & 8 deletions script/test/dist/cubing/node-import/main.js

This file was deleted.

8 changes: 0 additions & 8 deletions script/test/dist/cubing/scramble-all-events/main.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import { mkdtemp, readFile, stat } from "fs/promises";
import { join } from "path";
import { promisify } from "util";
import { gzip } from "zlib";
import { needFolder } from "../../../../lib/need-folder.js";
import { ESM_CLASS_PRIVATE_ESBUILD_SUPPORTED } from "../../../../build/targets.js"; // TODO: Factor out into the lib dir?
import { needFolder } from "../../../../../lib/need-folder.js";
import { ESM_CLASS_PRIVATE_ESBUILD_SUPPORTED } from "../../../../../build/targets.js"; // TODO: Factor out into the lib dir?

import { default as packageJSON } from "../../../../../package.json" assert {
import { default as packageJSON } from "../../../../../../package.json" assert {
type: "json",
};
const { exports } = packageJSON;

const rootPath = new URL("../../../../../", import.meta.url);
const rootPath = new URL("../../../../../../", import.meta.url);

needFolder(join(rootPath.pathname, "dist/npm/cubing"), "make build-esm");
needFolder(join(rootPath.pathname, "dist/lib/cubing"), "make build-esm");

function subpackageEntry(subpackageName) {
return new URL(exports[`./${subpackageName}`].import, rootPath).pathname;
Expand Down
11 changes: 11 additions & 0 deletions script/test/dist/lib/cubing/build-size/src/total.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export * as alg from "../../../../../../../dist/lib/cubing/alg";
export * as bluetooth from "../../../../../../../dist/lib/cubing/bluetooth";
export * as kpuzzle from "../../../../../../../dist/lib/cubing/kpuzzle";
export * as notation from "../../../../../../../dist/lib/cubing/notation";
export * as protocol from "../../../../../../../dist/lib/cubing/protocol";
export * as puzzleGeometry from "../../../../../../../dist/lib/cubing/puzzle-geometry";
export * as puzzles from "../../../../../../../dist/lib/cubing/puzzles";
export * as scramble from "../../../../../../../dist/lib/cubing/scramble";
export * as stream from "../../../../../../../dist/lib/cubing/stream";
export * as search from "../../../../../../../dist/lib/cubing/search";
export * as twisty from "../../../../../../../dist/lib/cubing/twisty";
8 changes: 8 additions & 0 deletions script/test/dist/lib/cubing/node-import/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { needFolder } from "../../../../../lib/need-folder.js";

needFolder(
new URL("../../../../../../dist/lib/cubing/alg", import.meta.url).pathname,
"make build-esm",
);

import("./test.js");
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { needFolder } from "../../../../lib/need-folder.js";
import { needFolder } from "../../../../../lib/need-folder.js";
needFolder(
new URL("../../../../../dist/npm/cubing/alg", import.meta.url).pathname,
new URL("../../../../../../dist/lib/cubing/alg", import.meta.url).pathname,
"make build-esm",
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { join } from "path";
import { stdout } from "process";
import { execPromiseLogged } from "../../../../lib/execPromise.js";
import { needFolder } from "../../../../lib/need-folder.js";
import { packageNames } from "../../../../lib/packages.js";
import { execPromiseLogged } from "../../../../../lib/execPromise.js";
import { needFolder } from "../../../../../lib/need-folder.js";
import { packageNames } from "../../../../../lib/packages.js";

// TODO: relative
const OUT_DIR = "./.temp/plain-esbuild-compat";

needFolder(
new URL("../../../../../dist/npm/cubing", import.meta.url).pathname,
new URL("../../../../../../dist/lib/cubing", import.meta.url).pathname,
"make build-esm",
);

const dist_entries = packageNames
.map((e) => join("dist/npm/cubing/", e, "/index.js"))
.map((e) => join("dist/lib/cubing/", e, "/index.js"))
.join(" ");
const cmd = `npx esbuild --bundle --splitting --outdir="${OUT_DIR}" --format=esm --minify ${dist_entries}`;
console.log(cmd);
Expand Down
9 changes: 9 additions & 0 deletions script/test/dist/lib/cubing/scramble-all-events/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { needFolder } from "../../../../../lib/need-folder.js";

needFolder(
new URL("../../../../../../dist/lib/cubing/scramble", import.meta.url)
.pathname,
"make build-esm",
);

import("./test.js");
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { needFolder } from "../../../../lib/need-folder.js";
import { needFolder } from "../../../../../lib/need-folder.js";
needFolder(
new URL("../../../../../dist/npm/cubing/kpuzzle", import.meta.url).pathname,
new URL("../../../../../../dist/lib/cubing/kpuzzle", import.meta.url)
.pathname,
"make build-esm",
);

import { chromium } from "playwright";
import { installServer, port, startServer } from "./serve-vite.js";
import { killAllChildProcesses } from "../../../../lib/execPromise.js";
import { killAllChildProcesses } from "../../../../../lib/execPromise.js";

const OPEN_REPL = false; // Set to `true` for testing.
const HEADLESS = !OPEN_REPL;
Expand Down
Loading

0 comments on commit 5937705

Please sign in to comment.