Skip to content

Commit 887578d

Browse files
Inject version identifiers in module builds
1 parent 12789d7 commit 887578d

File tree

3 files changed

+45
-5
lines changed

3 files changed

+45
-5
lines changed

packages/library/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@
6767
"build:js:coverage": "NODE_ENV=coverage webpack --mode=development",
6868
"build:js:development": "webpack --mode=development",
6969
"build:js:production": "webpack --mode=production",
70-
"build:js:esm": "tsc -m es6 --outDir dist/es6",
71-
"build:js:tsc": "tsc --outDir dist/es2022",
72-
"build:js": "yarn run build:js:development && yarn run build:js:production && (yarn run build:js:esm || true) && (yarn run build:js:tsc || true)",
70+
"build:js:esm": "(tsc -m es6 --outDir dist/es6 || true) && node scripts/postprocess_module_build.js",
71+
"build:js:tsc": "(tsc --outDir dist/es2022 || true) && node scripts/postprocess_module_build.js",
72+
"build:js": "yarn run build:js:development && yarn run build:js:production && yarn run build:js:esm && yarn run build:js:tsc",
7373
"build:css": "postcss --local-plugins -u postcss-preset-env -o dist/css/lab.css src/starterkit/lib/lab.css",
7474
"build:starterkit": "yarn run build:js && yarn run build:css && node scripts/bundle_starterkit.js",
7575
"clean": "shx rm -rf dist && shx mkdir dist",
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Inject variables into distribution code
2+
// (this was previously handled by webpack for the bundled library)
3+
const fs = require('fs')
4+
const shell = require('shelljs')
5+
6+
const files = [
7+
'dist/es6/index.js',
8+
'dist/es2022/index.js'
9+
]
10+
11+
const build_flavor = JSON.stringify('module')
12+
const build_commit = JSON.stringify(
13+
shell.exec('git rev-list -1 HEAD -- .', { silent: true }).trim(),
14+
)
15+
16+
files.map(f => {
17+
fs.readFile(f, 'utf8', (err, data) => {
18+
if (err) {
19+
if (err.code === 'ENOENT') {
20+
console.warn('Could not patch file', f, `which doesn't seem to exist`)
21+
return
22+
} else {
23+
throw err
24+
}
25+
}
26+
27+
let output = data.replace(
28+
/BUILD_FLAVOR/g,
29+
build_flavor
30+
)
31+
output = output.replace(
32+
/BUILD_COMMIT/g,
33+
build_commit
34+
)
35+
36+
fs.writeFile(f, output, 'utf8', (err) => {
37+
if (err) throw err
38+
})
39+
})
40+
})

packages/library/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
export const version = '22.0.0-beta10'
22
export const build = {
3-
//@ts-ignore Injected by webpack
3+
//@ts-ignore Injected during build
44
flavor: <string>BUILD_FLAVOR,
5-
//@ts-ignore Injected by webpack
5+
//@ts-ignore Injected during build
66
commit: <string>BUILD_COMMIT,
77
}
88

0 commit comments

Comments
 (0)