Skip to content

Commit

Permalink
build: stabilize build process
Browse files Browse the repository at this point in the history
  • Loading branch information
Xunnamius committed Jan 29, 2023
1 parent d07e9cc commit 6994784
Show file tree
Hide file tree
Showing 32 changed files with 196 additions and 201 deletions.
51 changes: 35 additions & 16 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,19 @@ const generateProductionEsmConfigObject = (mutateConfigFunction) => {
// ? We don't care about minification
],
plugins: [
/* // ? Ensure all local imports without extensions now end in .mjs
['add-import-extension', { extension: 'mjs' }],
// ? Fix ESM relative local imports referencing package.json
[
'transform-rename-import',
'transform-rewrite-imports',
{
replacements: [
{ original: '../package.json', replacement: `../../package.json` }
]
// ? Ensure all local imports without extensions now end in .mjs
appendExtension: '.mjs',
replaceExtensions: {
// ? Ensure built distributables can locate the package.json file
'^../package.json$': '../../package.json',
// ? Replace pkgverse imports with their runtime equivalents
'^pkgverse/([^/]+)/src/index$': '$1'
}
}
] */
]
]
};

Expand All @@ -44,9 +46,15 @@ const generateProductionEsmConfigObject = (mutateConfigFunction) => {

debug('NODE_ENV: %O', process.env.NODE_ENV);

/**
* @type {import('@babel/core').TransformOptions}
*/
module.exports = {
comments: false,
parserOpts: { strictMode: true },
assumptions: {
constantReexports: true
},
plugins: [
'@babel/plugin-proposal-export-default-from',
[
Expand Down Expand Up @@ -100,19 +108,30 @@ module.exports = {
],
['@babel/preset-typescript', { allowDeclareFields: true }]
// ? Minification is handled externally (e.g. by webpack)
] /* ,
plugins: [
// ? Interoperable named CJS imports for free
[
'transform-default-named-imports',
{ exclude: [/^next([/?#].+)?/, /^mongodb([/?#].+)?/] }
]
] */
]
},
// * Used by `npm run build` for compiling ESM to code output in ./dist
'production-esm': generateProductionEsmConfigObject((config) => {
config.presets[0][1].targets = NODE_LTS;
}),
// * Used by `npm run build` for fixing declaration file imports in ./dist
'production-types': {
comments: true,
plugins: [
['@babel/plugin-syntax-typescript', { dts: true }],
[
'transform-rewrite-imports',
{
replaceExtensions: {
// ? Ensure deep package.json imports resolve properly
'^../../../package.json$': '../../package.json',
// ? Ensure deep imports resolve properly
'^../../../(.*)$': '../$1'
}
}
]
]
},
// * Used by `npm run build-externals` for compiling to ESM code output in
// * ./external-scripts/bin
'production-external': generateProductionEsmConfigObject((config) => {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"repository": {
"type": "git",
"url": "https://github.com/Xunnamius/unified-utils",
"lens": "next"
"lens": "lib-esm"
},
"license": "MIT",
"workspaces": [
Expand All @@ -15,7 +15,7 @@
"__test:repeat:all": "echo 'Repeating test suite [initializing]...'; (i=0; while [ \"$((( i += 1 ) <= 100 ))\" -ne 0 ]; do sleep 0.1 && echo \"\\r\\033[1A\\033[0KRepeating test suite [run $i/100]...\" && JEST_SILENT_REPORTER_SHOW_WARNINGS=true NODE_ENV=test jest --reporters=jest-silent-reporter || exit; done) && echo \"All tests passed! Congrats!\"",
"__test:repeat:unit": "echo 'Repeating test suite [initializing]...'; (i=0; while [ \"$((( i += 1 ) <= 100 ))\" -ne 0 ]; do sleep 0.1 && echo \"\\r\\033[1A\\033[0KRepeating test suite [run $i/100]...\" && JEST_SILENT_REPORTER_SHOW_WARNINGS=true NODE_ENV=test jest --reporters=jest-silent-reporter --testPathIgnorePatterns test/integration-*.test.ts dist || exit; done) && echo \"All tests passed! Congrats!\"",
"clean": "git ls-files --exclude-standard --ignored --others --directory | grep -vE '^((\\.(env|vscode|husky))|next-env\\.d\\.ts|node_modules)($|\\/)' | xargs -p rm -rf",
"format": "MD_FILES=$(node -e 'console.log(require(`glob-gitignore`).sync(`**/*.md`, { ignore: require(`fs`).readFileSync(`.prettierignore`, `utf8`).split(`\n`).filter(Boolean), dot: true }).join(`\n`))') && (echo $MD_FILES | xargs remark --no-config --no-stdout --quiet --frail --use gfm --use lint-no-undefined-references || (echo -n '\u001b' && echo '[37;41;1m FAIL \u001b[0m cannot continue with undefined references present' && false)) && sort-package-json './package.json' './packages/*/package.json' && echo $MD_FILES | NODE_ENV=format xargs remark --output --frail && echo $MD_FILES | xargs doctoc --no-title --maxlevel 3 --update-only && echo $MD_FILES | xargs prettier --write",
"format": "MD_FILES=$(node -e 'console.log(require(`glob-gitignore`).sync(`**/*.md`, { ignore: require(`fs`).readFileSync(`.prettierignore`, `utf8`).split(`\n`).filter(Boolean), dot: true }).join(`\n`))') && (echo $MD_FILES | xargs remark --no-config --no-stdout --quiet --frail --use gfm --use lint-no-undefined-references || (echo -n '\u001b' && echo '[37;41;1m FAIL \u001b[0m cannot continue with undefined references present' && false)) && sort-package-json './package.json' './packages/*/package.json' && echo $MD_FILES | NODE_ENV=format xargs remark --output --frail && echo $MD_FILES | xargs doctoc --no-title --maxlevel 3 --update-only && prettier --write .",
"lint": "stdbuf -i0 -o0 -e0 tsc --project tsconfig.lint.json; X=$?; stdbuf -i0 -o0 -e0 eslint --parser-options=project:tsconfig.lint.json --no-error-on-unmatched-pattern packages src; Y=$?; MD_FILES=$(node -e 'console.log(require(`glob-gitignore`).sync(`**/*.md`, { ignore: require(`fs`).readFileSync(`.prettierignore`, `utf8`).split(`\n`).filter(Boolean), dot: true }).join(`\n`))') && echo $MD_FILES | NODE_ENV=lint xargs remark --quiet --frail --no-stdout; Z=$?; [ $X -eq 0 ] && [ $Y -eq 0 ] && [ $Z -eq 0 ]",
"lint:all": "stdbuf -i0 -o0 -e0 tsc --project tsconfig.eslint.json; X=$?; stdbuf -i0 -o0 -e0 eslint --parser-options=project:tsconfig.eslint.json .; Y=$?; MD_FILES=$(node -e 'console.log(require(`glob-gitignore`).sync(`**/*.md`, { ignore: require(`fs`).readFileSync(`.prettierignore`, `utf8`).split(`\n`).filter(Boolean), dot: true }).join(`\n`))') && echo $MD_FILES | NODE_ENV=lint xargs remark --quiet --frail --no-stdout; Z=$?; [ $X -eq 0 ] && [ $Y -eq 0 ] && [ $Z -eq 0 ]",
"list-tasks": "node -e 'console.log(Object.keys(require(\"./package.json\").scripts).join(\"\\n\"))' && npm run -ws list-tasks --if-present",
Expand Down
24 changes: 11 additions & 13 deletions packages/mdast-util-hidden/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@
"type": "commonjs",
"exports": {
".": {
"types": "./dist/index.d.ts",
"node": "./dist/index.mjs",
"default": "./dist/index.mjs"
"types": "./dist/src/index.d.ts",
"node": "./dist/src/index.mjs",
"default": "./dist/src/index.mjs"
},
"./package": "./package.json",
"./package.json": "./package.json"
},
"typesVersions": {
"*": {
"*": [
"./dist/index.d.ts"
"./dist/src/index.d.ts"
]
}
},
Expand All @@ -51,8 +51,8 @@
"scripts": {
"build": "npm run build:dist --",
"build:changelog": "conventional-changelog --outfile CHANGELOG.md --config ../../conventional.config.js --release-count 0 --skip-unstable && (if [ \"$CHANGELOG_SKIP_TITLE\" != 'true' ]; then { node -e 'console.log(require(\"../../conventional.config.js\").changelogTitle)'; cat CHANGELOG.md; } > CHANGELOG.md.ignore && mv CHANGELOG.md.ignore CHANGELOG.md; fi) && NODE_ENV=format remark --output --frail CHANGELOG.md && prettier --write CHANGELOG.md",
"build:dist": "NODE_ENV=production tsc --project tsconfig.types.json --incremental false && tsconfig-replace-paths --project tsconfig.types.json && NODE_ENV=production-esm babel src --extensions .ts --out-dir dist --out-file-extension .mjs --root-mode upward",
"build:docs": "if [ -r ./next.config.js ]; then typedoc --plugin typedoc-plugin-markdown --cleanOutputDir --tsconfig tsconfig.docs.json --out docs --readme none lib src test types external-scripts --exclude '**/*.test.*' --exclude external-scripts/bin; else ENTRY=`node -e 'const entry = require(\"./package.json\").config?.[\"plugin-build\"]?.docs?.entry; if(!entry) throw new Error(\"\\\"config['\"'\"'plugin-build'\"'\"'].docs.entry\\\" field is not defined in package.json\"); console.log(entry)'` && echo 'Entry file:' \"$ENTRY\" && typedoc --plugin typedoc-plugin-markdown --cleanOutputDir --tsconfig tsconfig.docs.json --out docs --readme none $(echo $ENTRY); fi",
"build:dist": "echo '> Generating types...' && NODE_ENV=production tsc --project tsconfig.types.json --incremental false && tsconfig-replace-paths --project tsconfig.types.json && echo '> Building distributables...' && NODE_ENV=production-esm babel src --extensions .ts --out-dir dist/src --out-file-extension .mjs --root-mode upward && echo '> Organizing types...' && cp --recursive --link --force --target-directory=dist dist/$(realpath --relative-base=../.. .)/* && rm --recursive --force dist/$(realpath --relative-base=../.. ..) && echo '> Refactoring types...' && NODE_ENV=production-types npx babel dist --extensions .ts --only '**/*.d.ts' --out-dir dist --keep-file-extension --root-mode upward",
"build:docs": "if [ -r ./next.config.js ]; then typedoc --plugin typedoc-plugin-markdown --cleanOutputDir --tsconfig tsconfig.docs.json --out docs --readme none lib src test types external-scripts --exclude '**/*.test.*' --exclude external-scripts/bin; else ENTRY=`node -e 'const entry = require(\"./package.json\").project?.documentation?.entry; if(!entry) throw new Error(\"\\\"project.documentation.entry\\\" field is not defined in package.json\"); console.log(entry)'` && echo 'Entry file:' \"$ENTRY\" && typedoc --plugin typedoc-plugin-markdown --cleanOutputDir --tsconfig tsconfig.docs.json --out docs --readme none $(echo $ENTRY); fi",
"clean": "git ls-files --exclude-standard --ignored --others --directory | grep -vE '^((\\.(env|vscode|husky))|next-env\\.d\\.ts|node_modules)($|\\/)' | xargs -p rm -rf",
"format": "cd ../.. && npm run format",
"lint": "echo 'IMPLEMENT ME'",
Expand All @@ -61,13 +61,6 @@
"test:integration": "echo 'IMPLEMENT ME'",
"test:unit": "echo 'IMPLEMENT ME'"
},
"config": {
"plugin-build": {
"docs": {
"entry": "./src/*"
}
}
},
"dependencies": {
"@types/mdast": "^3.0.10",
"@types/unist": "^2.0.6",
Expand All @@ -79,5 +72,10 @@
},
"publishConfig": {
"access": "public"
},
"project": {
"documentation": {
"entry": "./src/*"
}
}
}
2 changes: 1 addition & 1 deletion packages/mdast-util-hidden/tsconfig.types.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"isolatedModules": false,
"noEmit": false,
"outDir": "dist",
"rootDir": "./src"
"rootDir": "../../"
},
"extends": "../../tsconfig.json",
"include": ["../../types/**/*", "src/**/*"]
Expand Down
24 changes: 11 additions & 13 deletions packages/mdast-util-tight-comments/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@
"type": "commonjs",
"exports": {
".": {
"types": "./dist/index.d.ts",
"node": "./dist/index.mjs",
"default": "./dist/index.mjs"
"types": "./dist/src/index.d.ts",
"node": "./dist/src/index.mjs",
"default": "./dist/src/index.mjs"
},
"./package": "./package.json",
"./package.json": "./package.json"
},
"typesVersions": {
"*": {
"*": [
"./dist/index.d.ts"
"./dist/src/index.d.ts"
]
}
},
Expand All @@ -55,8 +55,8 @@
"scripts": {
"build": "npm run build:dist --",
"build:changelog": "conventional-changelog --outfile CHANGELOG.md --config ../../conventional.config.js --release-count 0 --skip-unstable && (if [ \"$CHANGELOG_SKIP_TITLE\" != 'true' ]; then { node -e 'console.log(require(\"../../conventional.config.js\").changelogTitle)'; cat CHANGELOG.md; } > CHANGELOG.md.ignore && mv CHANGELOG.md.ignore CHANGELOG.md; fi) && NODE_ENV=format remark --output --frail CHANGELOG.md && prettier --write CHANGELOG.md",
"build:dist": "NODE_ENV=production tsc --project tsconfig.types.json --incremental false && tsconfig-replace-paths --project tsconfig.types.json && NODE_ENV=production-esm babel src --extensions .ts --out-dir dist --out-file-extension .mjs --root-mode upward",
"build:docs": "if [ -r ./next.config.js ]; then typedoc --plugin typedoc-plugin-markdown --cleanOutputDir --tsconfig tsconfig.docs.json --out docs --readme none lib src test types external-scripts --exclude '**/*.test.*' --exclude external-scripts/bin; else ENTRY=`node -e 'const entry = require(\"./package.json\").config?.[\"plugin-build\"]?.docs?.entry; if(!entry) throw new Error(\"\\\"config['\"'\"'plugin-build'\"'\"'].docs.entry\\\" field is not defined in package.json\"); console.log(entry)'` && echo 'Entry file:' \"$ENTRY\" && typedoc --plugin typedoc-plugin-markdown --cleanOutputDir --tsconfig tsconfig.docs.json --out docs --readme none $(echo $ENTRY); fi",
"build:dist": "echo '> Generating types...' && NODE_ENV=production tsc --project tsconfig.types.json --incremental false && tsconfig-replace-paths --project tsconfig.types.json && echo '> Building distributables...' && NODE_ENV=production-esm babel src --extensions .ts --out-dir dist/src --out-file-extension .mjs --root-mode upward && echo '> Organizing types...' && cp --recursive --link --force --target-directory=dist dist/$(realpath --relative-base=../.. .)/* && rm --recursive --force dist/$(realpath --relative-base=../.. ..) && echo '> Refactoring types...' && NODE_ENV=production-types npx babel dist --extensions .ts --only '**/*.d.ts' --out-dir dist --keep-file-extension --root-mode upward",
"build:docs": "if [ -r ./next.config.js ]; then typedoc --plugin typedoc-plugin-markdown --cleanOutputDir --tsconfig tsconfig.docs.json --out docs --readme none lib src test types external-scripts --exclude '**/*.test.*' --exclude external-scripts/bin; else ENTRY=`node -e 'const entry = require(\"./package.json\").project?.documentation?.entry; if(!entry) throw new Error(\"\\\"project.documentation.entry\\\" field is not defined in package.json\"); console.log(entry)'` && echo 'Entry file:' \"$ENTRY\" && typedoc --plugin typedoc-plugin-markdown --cleanOutputDir --tsconfig tsconfig.docs.json --out docs --readme none $(echo $ENTRY); fi",
"clean": "git ls-files --exclude-standard --ignored --others --directory | grep -vE '^((\\.(env|vscode|husky))|next-env\\.d\\.ts|node_modules)($|\\/)' | xargs -p rm -rf",
"format": "cd ../.. && npm run format",
"lint": "echo 'IMPLEMENT ME'",
Expand All @@ -65,13 +65,6 @@
"test:integration": "echo 'IMPLEMENT ME'",
"test:unit": "echo 'IMPLEMENT ME'"
},
"config": {
"plugin-build": {
"docs": {
"entry": "./src/*"
}
}
},
"dependencies": {
"mdast-util-to-markdown": "^1.5.0"
},
Expand All @@ -80,5 +73,10 @@
},
"publishConfig": {
"access": "public"
},
"project": {
"documentation": {
"entry": "./src/*"
}
}
}
2 changes: 1 addition & 1 deletion packages/mdast-util-tight-comments/tsconfig.types.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"isolatedModules": false,
"noEmit": false,
"outDir": "dist",
"rootDir": "./src"
"rootDir": "../../"
},
"extends": "../../tsconfig.json",
"include": ["../../types/**/*", "src/**/*"]
Expand Down
24 changes: 11 additions & 13 deletions packages/remark-capitalize-headings/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@
"type": "commonjs",
"exports": {
".": {
"types": "./dist/index.d.ts",
"node": "./dist/index.mjs",
"default": "./dist/index.mjs"
"types": "./dist/src/index.d.ts",
"node": "./dist/src/index.mjs",
"default": "./dist/src/index.mjs"
},
"./package": "./package.json",
"./package.json": "./package.json"
},
"typesVersions": {
"*": {
"*": [
"./dist/index.d.ts"
"./dist/src/index.d.ts"
]
}
},
Expand All @@ -50,8 +50,8 @@
"scripts": {
"build": "npm run build:dist --",
"build:changelog": "conventional-changelog --outfile CHANGELOG.md --config ../../conventional.config.js --release-count 0 --skip-unstable && (if [ \"$CHANGELOG_SKIP_TITLE\" != 'true' ]; then { node -e 'console.log(require(\"../../conventional.config.js\").changelogTitle)'; cat CHANGELOG.md; } > CHANGELOG.md.ignore && mv CHANGELOG.md.ignore CHANGELOG.md; fi) && NODE_ENV=format remark --output --frail CHANGELOG.md && prettier --write CHANGELOG.md",
"build:dist": "NODE_ENV=production tsc --project tsconfig.types.json --incremental false && tsconfig-replace-paths --project tsconfig.types.json && NODE_ENV=production-esm babel src --extensions .ts --out-dir dist --out-file-extension .mjs --root-mode upward",
"build:docs": "if [ -r ./next.config.js ]; then typedoc --plugin typedoc-plugin-markdown --cleanOutputDir --tsconfig tsconfig.docs.json --out docs --readme none lib src test types external-scripts --exclude '**/*.test.*' --exclude external-scripts/bin; else ENTRY=`node -e 'const entry = require(\"./package.json\").config?.[\"plugin-build\"]?.docs?.entry; if(!entry) throw new Error(\"\\\"config['\"'\"'plugin-build'\"'\"'].docs.entry\\\" field is not defined in package.json\"); console.log(entry)'` && echo 'Entry file:' \"$ENTRY\" && typedoc --plugin typedoc-plugin-markdown --cleanOutputDir --tsconfig tsconfig.docs.json --out docs --readme none $(echo $ENTRY); fi",
"build:dist": "echo '> Generating types...' && NODE_ENV=production tsc --project tsconfig.types.json --incremental false && tsconfig-replace-paths --project tsconfig.types.json && echo '> Building distributables...' && NODE_ENV=production-esm babel src --extensions .ts --out-dir dist/src --out-file-extension .mjs --root-mode upward && echo '> Organizing types...' && cp --recursive --link --force --target-directory=dist dist/$(realpath --relative-base=../.. .)/* && rm --recursive --force dist/$(realpath --relative-base=../.. ..) && echo '> Refactoring types...' && NODE_ENV=production-types npx babel dist --extensions .ts --only '**/*.d.ts' --out-dir dist --keep-file-extension --root-mode upward",
"build:docs": "if [ -r ./next.config.js ]; then typedoc --plugin typedoc-plugin-markdown --cleanOutputDir --tsconfig tsconfig.docs.json --out docs --readme none lib src test types external-scripts --exclude '**/*.test.*' --exclude external-scripts/bin; else ENTRY=`node -e 'const entry = require(\"./package.json\").project?.documentation?.entry; if(!entry) throw new Error(\"\\\"project.documentation.entry\\\" field is not defined in package.json\"); console.log(entry)'` && echo 'Entry file:' \"$ENTRY\" && typedoc --plugin typedoc-plugin-markdown --cleanOutputDir --tsconfig tsconfig.docs.json --out docs --readme none $(echo $ENTRY); fi",
"clean": "git ls-files --exclude-standard --ignored --others --directory | grep -vE '^((\\.(env|vscode|husky))|next-env\\.d\\.ts|node_modules)($|\\/)' | xargs -p rm -rf",
"format": "cd ../.. && npm run format",
"lint": "echo 'IMPLEMENT ME'",
Expand All @@ -60,13 +60,6 @@
"test:integration": "echo 'IMPLEMENT ME'",
"test:unit": "echo 'IMPLEMENT ME'"
},
"config": {
"plugin-build": {
"docs": {
"entry": "./src/*"
}
}
},
"dependencies": {
"@types/mdast": "^3.0.10",
"mdast-util-to-string": "^3.1.1",
Expand All @@ -79,5 +72,10 @@
},
"publishConfig": {
"access": "public"
},
"project": {
"documentation": {
"entry": "./src/*"
}
}
}
2 changes: 1 addition & 1 deletion packages/remark-capitalize-headings/tsconfig.types.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"isolatedModules": false,
"noEmit": false,
"outDir": "dist",
"rootDir": "./src"
"rootDir": "../../"
},
"extends": "../../tsconfig.json",
"include": ["../../types/**/*", "src/**/*"]
Expand Down
Loading

0 comments on commit 6994784

Please sign in to comment.