Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the build. Split dev from prod. In dev, convert import.meta.env.DEV to DEBUG from @glimmer/env #1472

Merged
merged 12 commits into from
Oct 30, 2023
3 changes: 3 additions & 0 deletions bin/clean.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { rimraf } from 'rimraf';

await rimraf('**/{dist,.turbo,node_modules}/', { glob: true });
13 changes: 7 additions & 6 deletions bin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
"name": "@glimmer-workspace/bin",
"private": true,
"dependencies": {
"puppeteer-chromium-resolver": "^20.0.0",
"chalk": "^5.2.0",
"execa": "^7.1.1",
"js-yaml": "^4.1.0",
"glob": "^10.2.3",
"@types/glob": "^8.1.0",
"@types/js-yaml": "^4.0.5",
"@types/node": "^18.16.7",
"@types/puppeteer-chromium-resolver": "workspace:^"
"@types/puppeteer-chromium-resolver": "workspace:^",
"chalk": "^5.2.0",
"execa": "^7.1.1",
"glob": "^10.2.3",
"js-yaml": "^4.1.0",
"puppeteer-chromium-resolver": "^20.0.0",
"rimraf": "^5.0.0"
},
"devDependencies": {
"eslint": "^8.52.0",
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"license": "MIT",
"author": "Tilde, Inc.",
"scripts": {
"clean": "node ./bin/clean.mjs",
"benchmark:build": "node benchmark/bin/build.js",
"benchmark:control": "node benchmark/bin/control.js",
"benchmark:experiment": "node benchmark/bin/experiment.js",
Expand All @@ -20,7 +21,7 @@
"build:control": "rollup -c rollup.config.mjs",
"build:flags": "RETAIN_FLAGS=true ember build --env production --suppress-sizes",
"lint": "npm-run-all lint:*",
"lint:files": "dotenv -- turbo test:lint",
"lint:files": "dotenv -- turbo lint",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lint now depends on publint, which also depends on build.
in another PR, I'll be adding an in-CI turbo server to help with build times

"force:lint:files": "eslint .",
"lint:types": "tsc -b",
"start": "ember serve --port=7357",
Expand Down
60 changes: 34 additions & 26 deletions packages/@glimmer-workspace/build/lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import { fileURLToPath } from 'node:url';

import rollupTS from 'rollup-plugin-ts';
import ts from 'typescript';

import replace from '@rollup/plugin-replace';
import * as insert from 'rollup-plugin-insert';
import importMeta from './import-meta.js';
import inline from './inline.js';

Expand Down Expand Up @@ -243,7 +244,7 @@ export class Package {
* @returns {import("rollup").RollupOptions[] | import("rollup").RollupOptions}
*/
config() {
return [...this.rollupESM(), ...this.rollupCJS()];
return [...this.rollupESM({ env: 'dev' }), ...this.rollupESM({ env: 'prod' })];
}

/**
Expand Down Expand Up @@ -272,18 +273,22 @@ export class Package {
}

/**
* @typedef {object} RollupConfigurationOptions
* @property {'dev' | 'prod'} env
*
* @param {RollupConfigurationOptions} options
* @returns {RollupOptions[]}
*/
rollupESM() {
return this.#shared('esm').map((options) => ({
rollupESM({ env }) {
return this.#shared('esm', env).map((options) => ({
...options,
external: this.#external,
plugins: [
inline(),
nodePolyfills(),
commonjs(),
nodeResolve(),
importMeta,
...this.replacements(env),
postcss(),
typescript(this.#package, {
target: ScriptTarget.ES2022,
Expand All @@ -294,26 +299,28 @@ export class Package {
}

/**
* @returns {import("rollup").RollupOptions[]}
* We only want importMeta stripped for production builds
* @param {'dev' | 'prod'} env
* @returns {any}
*/
rollupCJS() {
return this.#shared('cjs').map((options) => ({
...options,
external: this.#external,
plugins: [
inline(),
nodePolyfills(),
commonjs(),
nodeResolve(),
importMeta,
postcss(),
typescript(this.#package, {
target: ScriptTarget.ES2021,
module: ModuleKind.CommonJS,
moduleResolution: ModuleResolutionKind.NodeJs,
}),
],
}));
replacements(env) {
return env === 'prod'
? [importMeta]
: [
replace({
preventAssignment: true,
values: {
'import.meta.env.DEV': 'DEBUG',
'import.meta.env.PROD': '!DEBUG',
},
}),
insert.transform((_magicString, code, _id) => {
if (code.includes('DEBUG')) {
return `import { DEBUG } from '@glimmer/env';\n` + code;
}
return code;
}),
];
}

/**
Expand All @@ -338,9 +345,10 @@ export class Package {

/**
* @param {"esm" | "cjs"} format
* @param {"dev" | "prod"} env
* @returns {import("rollup").RollupOptions[]}
*/
#shared(format) {
#shared(format, env) {
const { root, main } = this.#package;

const ext = format === 'esm' ? 'js' : 'cjs';
Expand All @@ -358,7 +366,7 @@ export class Package {
return {
input: resolve(root, ts),
output: {
file: resolve(root, 'dist', file),
file: resolve(root, 'dist', env, file),
format,
sourcemap: true,
exports: format === 'cjs' ? 'named' : 'auto',
Expand Down
2 changes: 2 additions & 0 deletions packages/@glimmer-workspace/build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"dependencies": {
"@rollup/plugin-commonjs": "^24.1.0",
"@rollup/plugin-node-resolve": "^15.0.2",
"@rollup/plugin-replace": "^5.0.4",
"eslint": "^8.52.0",
"eslint-plugin-import": "^2.29.0",
"eslint-plugin-json": "^3.1.0",
Expand All @@ -31,6 +32,7 @@
"magic-string": "^0.30.0",
"postcss": "^8.4.31",
"rollup": "^3.21.6",
"rollup-plugin-insert": "^1.3.2",
"rollup-plugin-polyfill-node": "^0.12.0",
"rollup-plugin-postcss": "^4.0.2",
"rollup-plugin-ts": "^3.2.0",
Expand Down
20 changes: 13 additions & 7 deletions packages/@glimmer/compiler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@
],
"publishConfig": {
"access": "public",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"main": "dist/prod/index.js",
"types": "dist/dev/index.d.ts",
"exports": {
"types": "./dist/index.d.ts",
"require": "./dist/index.cjs",
"default": "./dist/index.js"
".": {
"types": "./dist/dev/index.d.ts",
"development": {
"default": "./dist/dev/index.js"
},
"default": "./dist/prod/index.js"
}
}
},
"dependencies": {
Expand All @@ -36,12 +40,14 @@
"rollup": "^3.21.6",
"@glimmer/local-debug-flags": "workspace:^",
"@glimmer-workspace/build-support": "workspace:^",
"@types/node": "^18.16.6"
"@types/node": "^18.16.6",
"publint": "^0.2.5"
},
"scripts": {
"build": "rollup -c rollup.config.mjs",
"test:lint": "eslint .",
"test:types": "tsc --noEmit -p ../tsconfig.json"
"test:types": "tsc --noEmit -p ../tsconfig.json",
"test:publint": "publint"
},
"main": "index.ts",
"types": "index.ts"
Expand Down
20 changes: 13 additions & 7 deletions packages/@glimmer/debug/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@
],
"publishConfig": {
"access": "public",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"main": "dist/prod/index.js",
"types": "dist/dev/index.d.ts",
"exports": {
"types": "./dist/index.d.ts",
"require": "./dist/index.cjs",
"default": "./dist/index.js"
".": {
"types": "./dist/dev/index.d.ts",
"development": {
"default": "./dist/dev/index.js"
},
"default": "./dist/prod/index.js"
}
}
},
"dependencies": {
Expand All @@ -32,11 +36,13 @@
"rollup": "^3.21.6",
"@glimmer/local-debug-flags": "workspace:^",
"toml": "^3.0.0",
"@glimmer-workspace/build-support": "workspace:^"
"@glimmer-workspace/build-support": "workspace:^",
"publint": "^0.2.5"
},
"scripts": {
"test:lint": "eslint .",
"test:types": "tsc --noEmit -p ../tsconfig.json",
"build": "rollup -c rollup.config.mjs"
"build": "rollup -c rollup.config.mjs",
"test:publint": "publint"
}
}
20 changes: 13 additions & 7 deletions packages/@glimmer/destroyable/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@
],
"publishConfig": {
"access": "public",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"main": "dist/prod/index.js",
"types": "dist/dev/index.d.ts",
"exports": {
"types": "./dist/index.d.ts",
"require": "./dist/index.cjs",
"default": "./dist/index.js"
".": {
"types": "./dist/dev/index.d.ts",
"development": {
"default": "./dist/dev/index.js"
},
"default": "./dist/prod/index.js"
}
}
},
"dependencies": {
Expand All @@ -30,11 +34,13 @@
"eslint": "^8.52.0",
"rollup": "^3.21.6",
"@glimmer/local-debug-flags": "workspace:^",
"@glimmer-workspace/build-support": "workspace:^"
"@glimmer-workspace/build-support": "workspace:^",
"publint": "^0.2.5"
},
"scripts": {
"test:lint": "eslint .",
"test:types": "tsc --noEmit -p ../tsconfig.json",
"build": "rollup -c rollup.config.mjs"
"build": "rollup -c rollup.config.mjs",
"test:publint": "publint"
}
}
20 changes: 13 additions & 7 deletions packages/@glimmer/dom-change-list/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
"types": "index.ts",
"publishConfig": {
"access": "public",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"main": "dist/prod/index.js",
"types": "dist/dev/index.d.ts",
"exports": {
"types": "./dist/index.d.ts",
"require": "./dist/index.cjs",
"default": "./dist/index.js"
".": {
"types": "./dist/dev/index.d.ts",
"development": {
"default": "./dist/dev/index.js"
},
"default": "./dist/prod/index.js"
}
}
},
"files": [
Expand All @@ -26,11 +30,13 @@
"eslint": "^8.52.0",
"rollup": "^3.21.6",
"@glimmer/local-debug-flags": "workspace:^",
"@glimmer-workspace/build-support": "workspace:^"
"@glimmer-workspace/build-support": "workspace:^",
"publint": "^0.2.5"
},
"scripts": {
"test:lint": "eslint .",
"test:types": "tsc --noEmit -p ../tsconfig.json",
"build": "rollup -c rollup.config.mjs"
"build": "rollup -c rollup.config.mjs",
"test:publint": "publint"
}
}
20 changes: 13 additions & 7 deletions packages/@glimmer/encoder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
"types": "index.ts",
"publishConfig": {
"access": "public",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"main": "dist/prod/index.js",
"types": "dist/dev/index.d.ts",
"exports": {
"types": "./dist/index.d.ts",
"require": "./dist/index.cjs",
"default": "./dist/index.js"
".": {
"types": "./dist/dev/index.d.ts",
"development": {
"default": "./dist/dev/index.js"
},
"default": "./dist/prod/index.js"
}
}
},
"files": [
Expand All @@ -25,11 +29,13 @@
"scripts": {
"test:lint": "eslint .",
"test:types": "tsc --noEmit -p ../tsconfig.json",
"build": "rollup -c rollup.config.mjs"
"build": "rollup -c rollup.config.mjs",
"test:publint": "publint"
},
"devDependencies": {
"eslint": "^8.52.0",
"rollup": "^3.21.6",
"@glimmer-workspace/build-support": "workspace:^"
"@glimmer-workspace/build-support": "workspace:^",
"publint": "^0.2.5"
}
}
18 changes: 11 additions & 7 deletions packages/@glimmer/global-context/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,26 @@
],
"publishConfig": {
"access": "public",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"exports": {
"types": "./dist/index.d.ts",
"require": "./dist/index.cjs",
"default": "./dist/index.js"
".": {
"types": "./dist/dev/index.d.ts",
"development": {
"default": "./dist/dev/index.js"
},
"default": "./dist/prod/index.js"
}
}
},
"scripts": {
"test:lint": "eslint .",
"test:types": "tsc --noEmit -p ../tsconfig.json",
"build": "rollup -c rollup.config.mjs"
"build": "rollup -c rollup.config.mjs",
"test:publint": "publint"
},
"devDependencies": {
"eslint": "^8.52.0",
"rollup": "^3.21.6",
"@glimmer-workspace/build-support": "workspace:^"
"@glimmer-workspace/build-support": "workspace:^",
"publint": "^0.2.5"
}
}
Loading