Skip to content

Commit

Permalink
meta: add support for ESM sources in build script
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 committed Feb 7, 2022
1 parent 142b95a commit a73869a
Show file tree
Hide file tree
Showing 3 changed files with 195 additions and 14 deletions.
19 changes: 12 additions & 7 deletions bin/build-lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const path = require('path')

const { mkdir, stat, writeFile } = fs.promises

const SOURCE = 'packages/{*,@uppy/*}/src/**/*.js'
const SOURCE = 'packages/{*,@uppy/*}/src/**/*.js?(x)'
// Files not to build (such as tests)
const IGNORE = /\.test\.js$|__mocks__|svelte|angular|companion\//
// Files that should trigger a rebuild of everything on change
Expand All @@ -19,9 +19,12 @@ const META_FILES = [
'bin/build-lib.js',
]

function lastModified (file) {
return stat(file).then((s) => s.mtime, (err) => {
function lastModified (file, createParentDir = false) {
return stat(file).then((s) => s.mtime, async (err) => {
if (err.code === 'ENOENT') {
if (createParentDir) {
await mkdir(path.dirname(file), { recursive: true })
}
return 0
}
throw err
Expand All @@ -42,17 +45,19 @@ async function buildLib () {

// on a fresh build, rebuild everything.
if (!process.env.FRESH) {
const srcMtime = await lastModified(file)
const libMtime = await lastModified(libFile)
.catch(() => 0) // probably doesn't exist
const [srcMtime, libMtime] = await Promise.all([
lastModified(file),
lastModified(libFile, true),
])
// Skip files that haven't changed
if (srcMtime < libMtime && metaMtime < libMtime) {
continue
}
} else {
await mkdir(path.dirname(libFile), { recursive: true })
}

const { code, map } = await babel.transformFileAsync(file, { sourceMaps: true })
await mkdir(path.dirname(libFile), { recursive: true })
await Promise.all([
writeFile(libFile, code),
writeFile(`${libFile}.map`, JSON.stringify(map)),
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"@babel/eslint-plugin": "^7.11.3",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.14.5",
"@babel/plugin-proposal-optional-chaining": "^7.16.0",
"@babel/plugin-transform-modules-commonjs": "^7.16.8",
"@babel/plugin-transform-react-jsx": "^7.10.4",
"@babel/preset-env": "^7.14.7",
"@babel/register": "^7.10.5",
Expand Down
189 changes: 182 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,15 @@ __metadata:
languageName: node
linkType: hard

"@babel/code-frame@npm:^7.16.7":
version: 7.16.7
resolution: "@babel/code-frame@npm:7.16.7"
dependencies:
"@babel/highlight": ^7.16.7
checksum: db2f7faa31bc2c9cf63197b481b30ea57147a5fc1a6fab60e5d6c02cdfbf6de8e17b5121f99917b3dabb5eeb572da078312e70697415940383efc140d4e0808b
languageName: node
linkType: hard

"@babel/compat-data@npm:^7.12.13, @babel/compat-data@npm:^7.13.11, @babel/compat-data@npm:^7.15.0, @babel/compat-data@npm:^7.16.0, @babel/compat-data@npm:^7.16.4":
version: 7.16.4
resolution: "@babel/compat-data@npm:7.16.4"
Expand Down Expand Up @@ -713,6 +722,17 @@ __metadata:
languageName: node
linkType: hard

"@babel/generator@npm:^7.17.0":
version: 7.17.0
resolution: "@babel/generator@npm:7.17.0"
dependencies:
"@babel/types": ^7.17.0
jsesc: ^2.5.1
source-map: ^0.5.0
checksum: 2987dbebb484727a227f1ce3db90810320986cfb3ffd23e6d1d87f75bbd8e7871b5bc44252822d4d5f048a2d872a5702b2a9bf7bab7e07f087d7f306f0ea6c0a
languageName: node
linkType: hard

"@babel/helper-annotate-as-pure@npm:7.15.4":
version: 7.15.4
resolution: "@babel/helper-annotate-as-pure@npm:7.15.4"
Expand Down Expand Up @@ -837,6 +857,15 @@ __metadata:
languageName: node
linkType: hard

"@babel/helper-environment-visitor@npm:^7.16.7":
version: 7.16.7
resolution: "@babel/helper-environment-visitor@npm:7.16.7"
dependencies:
"@babel/types": ^7.16.7
checksum: c03a10105d9ebd1fe632a77356b2e6e2f3c44edba9a93b0dc3591b6a66bd7a2e323dd9502f9ce96fc6401234abff1907aa877b6674f7826b61c953f7c8204bbe
languageName: node
linkType: hard

"@babel/helper-explode-assignable-expression@npm:^7.16.0":
version: 7.16.0
resolution: "@babel/helper-explode-assignable-expression@npm:7.16.0"
Expand All @@ -857,6 +886,17 @@ __metadata:
languageName: node
linkType: hard

"@babel/helper-function-name@npm:^7.16.7":
version: 7.16.7
resolution: "@babel/helper-function-name@npm:7.16.7"
dependencies:
"@babel/helper-get-function-arity": ^7.16.7
"@babel/template": ^7.16.7
"@babel/types": ^7.16.7
checksum: fc77cbe7b10cfa2a262d7a37dca575c037f20419dfe0c5d9317f589599ca24beb5f5c1057748011159149eaec47fe32338c6c6412376fcded68200df470161e1
languageName: node
linkType: hard

"@babel/helper-get-function-arity@npm:^7.16.0":
version: 7.16.0
resolution: "@babel/helper-get-function-arity@npm:7.16.0"
Expand All @@ -866,6 +906,15 @@ __metadata:
languageName: node
linkType: hard

"@babel/helper-get-function-arity@npm:^7.16.7":
version: 7.16.7
resolution: "@babel/helper-get-function-arity@npm:7.16.7"
dependencies:
"@babel/types": ^7.16.7
checksum: 25d969fb207ff2ad5f57a90d118f6c42d56a0171022e200aaa919ba7dc95ae7f92ec71cdea6c63ef3629a0dc962ab4c78e09ca2b437185ab44539193f796e0c3
languageName: node
linkType: hard

"@babel/helper-hoist-variables@npm:^7.16.0":
version: 7.16.0
resolution: "@babel/helper-hoist-variables@npm:7.16.0"
Expand All @@ -875,6 +924,15 @@ __metadata:
languageName: node
linkType: hard

"@babel/helper-hoist-variables@npm:^7.16.7":
version: 7.16.7
resolution: "@babel/helper-hoist-variables@npm:7.16.7"
dependencies:
"@babel/types": ^7.16.7
checksum: 6ae1641f4a751cd9045346e3f61c3d9ec1312fd779ab6d6fecfe2a96e59a481ad5d7e40d2a840894c13b3fd6114345b157f9e3062fc5f1580f284636e722de60
languageName: node
linkType: hard

"@babel/helper-member-expression-to-functions@npm:^7.16.0":
version: 7.16.0
resolution: "@babel/helper-member-expression-to-functions@npm:7.16.0"
Expand All @@ -893,6 +951,15 @@ __metadata:
languageName: node
linkType: hard

"@babel/helper-module-imports@npm:^7.16.7":
version: 7.16.7
resolution: "@babel/helper-module-imports@npm:7.16.7"
dependencies:
"@babel/types": ^7.16.7
checksum: ddd2c4a600a2e9a4fee192ab92bf35a627c5461dbab4af31b903d9ba4d6b6e59e0ff3499fde4e2e9a0eebe24906f00b636f8b4d9bd72ff24d50e6618215c3212
languageName: node
linkType: hard

"@babel/helper-module-transforms@npm:^7.12.1, @babel/helper-module-transforms@npm:^7.15.8, @babel/helper-module-transforms@npm:^7.16.0, @babel/helper-module-transforms@npm:^7.9.0":
version: 7.16.0
resolution: "@babel/helper-module-transforms@npm:7.16.0"
Expand All @@ -909,6 +976,22 @@ __metadata:
languageName: node
linkType: hard

"@babel/helper-module-transforms@npm:^7.16.7":
version: 7.16.7
resolution: "@babel/helper-module-transforms@npm:7.16.7"
dependencies:
"@babel/helper-environment-visitor": ^7.16.7
"@babel/helper-module-imports": ^7.16.7
"@babel/helper-simple-access": ^7.16.7
"@babel/helper-split-export-declaration": ^7.16.7
"@babel/helper-validator-identifier": ^7.16.7
"@babel/template": ^7.16.7
"@babel/traverse": ^7.16.7
"@babel/types": ^7.16.7
checksum: 6e930ce776c979f299cdbeaf80187f4ab086d75287b96ecc1c6896d392fcb561065f0d6219fc06fa79b4ceb4bbdc1a9847da8099aba9b077d0a9e583500fb673
languageName: node
linkType: hard

"@babel/helper-optimise-call-expression@npm:^7.16.0":
version: 7.16.0
resolution: "@babel/helper-optimise-call-expression@npm:7.16.0"
Expand All @@ -932,6 +1015,13 @@ __metadata:
languageName: node
linkType: hard

"@babel/helper-plugin-utils@npm:^7.16.7":
version: 7.16.7
resolution: "@babel/helper-plugin-utils@npm:7.16.7"
checksum: d08dd86554a186c2538547cd537552e4029f704994a9201d41d82015c10ed7f58f9036e8d1527c3760f042409163269d308b0b3706589039c5f1884619c6d4ce
languageName: node
linkType: hard

"@babel/helper-remap-async-to-generator@npm:^7.14.5, @babel/helper-remap-async-to-generator@npm:^7.15.4, @babel/helper-remap-async-to-generator@npm:^7.16.0, @babel/helper-remap-async-to-generator@npm:^7.16.4":
version: 7.16.4
resolution: "@babel/helper-remap-async-to-generator@npm:7.16.4"
Expand Down Expand Up @@ -964,6 +1054,15 @@ __metadata:
languageName: node
linkType: hard

"@babel/helper-simple-access@npm:^7.16.7":
version: 7.16.7
resolution: "@babel/helper-simple-access@npm:7.16.7"
dependencies:
"@babel/types": ^7.16.7
checksum: 8d22c46c5ec2ead0686c4d5a3d1d12b5190c59be676bfe0d9d89df62b437b51d1a3df2ccfb8a77dded2e585176ebf12986accb6d45a18cff229eef3b10344f4b
languageName: node
linkType: hard

"@babel/helper-skip-transparent-expression-wrappers@npm:^7.16.0":
version: 7.16.0
resolution: "@babel/helper-skip-transparent-expression-wrappers@npm:7.16.0"
Expand All @@ -982,13 +1081,29 @@ __metadata:
languageName: node
linkType: hard

"@babel/helper-split-export-declaration@npm:^7.16.7":
version: 7.16.7
resolution: "@babel/helper-split-export-declaration@npm:7.16.7"
dependencies:
"@babel/types": ^7.16.7
checksum: e10aaf135465c55114627951b79115f24bc7af72ecbb58d541d66daf1edaee5dde7cae3ec8c3639afaf74526c03ae3ce723444e3b5b3dc77140c456cd84bcaa1
languageName: node
linkType: hard

"@babel/helper-validator-identifier@npm:^7.15.7":
version: 7.15.7
resolution: "@babel/helper-validator-identifier@npm:7.15.7"
checksum: f041c28c531d1add5cc345b25d5df3c29c62bce3205b4d4a93dcd164ccf630350acba252d374fad8f5d8ea526995a215829f27183ba7ce7ce141843bf23068a6
languageName: node
linkType: hard

"@babel/helper-validator-identifier@npm:^7.16.7":
version: 7.16.7
resolution: "@babel/helper-validator-identifier@npm:7.16.7"
checksum: dbb3db9d184343152520a209b5684f5e0ed416109cde82b428ca9c759c29b10c7450657785a8b5c5256aa74acc6da491c1f0cf6b784939f7931ef82982051b69
languageName: node
linkType: hard

"@babel/helper-validator-option@npm:^7.12.17, @babel/helper-validator-option@npm:^7.14.5":
version: 7.14.5
resolution: "@babel/helper-validator-option@npm:7.14.5"
Expand Down Expand Up @@ -1030,6 +1145,17 @@ __metadata:
languageName: node
linkType: hard

"@babel/highlight@npm:^7.16.7":
version: 7.16.10
resolution: "@babel/highlight@npm:7.16.10"
dependencies:
"@babel/helper-validator-identifier": ^7.16.7
chalk: ^2.0.0
js-tokens: ^4.0.0
checksum: 1f1bdd752a90844f4efc22166a46303fb651ba0fd75a06daba3ebae2575ab3edc1da9827c279872a3aaf305f50a18473c5fa1966752726a2b253065fd4c0745e
languageName: node
linkType: hard

"@babel/parser@npm:^7.0.0, @babel/parser@npm:^7.1.0, @babel/parser@npm:^7.12.11, @babel/parser@npm:^7.12.7, @babel/parser@npm:^7.14.7, @babel/parser@npm:^7.15.0, @babel/parser@npm:^7.15.4, @babel/parser@npm:^7.15.8, @babel/parser@npm:^7.16.0, @babel/parser@npm:^7.16.3, @babel/parser@npm:^7.7.2, @babel/parser@npm:^7.9.0":
version: 7.16.4
resolution: "@babel/parser@npm:7.16.4"
Expand All @@ -1039,6 +1165,15 @@ __metadata:
languageName: node
linkType: hard

"@babel/parser@npm:^7.16.7, @babel/parser@npm:^7.17.0":
version: 7.17.0
resolution: "@babel/parser@npm:7.17.0"
bin:
parser: ./bin/babel-parser.js
checksum: d0ac5ffba0b234dde516f867edf5da5d92d6f841592b370ae3244cd7c8f27a7f5e3e3d4e90ca9c15ea58bc46823f1643f3f75b6eb9a9f676ae16e8b2365e922a
languageName: node
linkType: hard

"@babel/plugin-bugfix-safari-id-destructuring-collision-in-function-expression@npm:^7.16.2":
version: 7.16.2
resolution: "@babel/plugin-bugfix-safari-id-destructuring-collision-in-function-expression@npm:7.16.2"
Expand Down Expand Up @@ -1770,17 +1905,17 @@ __metadata:
languageName: node
linkType: hard

"@babel/plugin-transform-modules-commonjs@npm:^7.0.0, @babel/plugin-transform-modules-commonjs@npm:^7.12.13, @babel/plugin-transform-modules-commonjs@npm:^7.15.4, @babel/plugin-transform-modules-commonjs@npm:^7.16.0, @babel/plugin-transform-modules-commonjs@npm:^7.4.4":
version: 7.16.0
resolution: "@babel/plugin-transform-modules-commonjs@npm:7.16.0"
"@babel/plugin-transform-modules-commonjs@npm:^7.0.0, @babel/plugin-transform-modules-commonjs@npm:^7.12.13, @babel/plugin-transform-modules-commonjs@npm:^7.15.4, @babel/plugin-transform-modules-commonjs@npm:^7.16.0, @babel/plugin-transform-modules-commonjs@npm:^7.16.8, @babel/plugin-transform-modules-commonjs@npm:^7.4.4":
version: 7.16.8
resolution: "@babel/plugin-transform-modules-commonjs@npm:7.16.8"
dependencies:
"@babel/helper-module-transforms": ^7.16.0
"@babel/helper-plugin-utils": ^7.14.5
"@babel/helper-simple-access": ^7.16.0
"@babel/helper-module-transforms": ^7.16.7
"@babel/helper-plugin-utils": ^7.16.7
"@babel/helper-simple-access": ^7.16.7
babel-plugin-dynamic-import-node: ^2.3.3
peerDependencies:
"@babel/core": ^7.0.0-0
checksum: a7e43670f503b31d6ad42977ddefb7bffc23f700a24252859652aa03efd666698567b0817060dd6f84a6cd23e7aac7464bc0dc7f7f929cad212263abcac9d470
checksum: c0ac00f5457e12cac7825b14725b6fc787bef78945181469ff79f07ef0fd7df021cb00fe1d3a9f35fc9bc92ae59e6e3fc9075a70b627dfe10e00d0907892aace
languageName: node
linkType: hard

Expand Down Expand Up @@ -2460,6 +2595,17 @@ __metadata:
languageName: node
linkType: hard

"@babel/template@npm:^7.16.7":
version: 7.16.7
resolution: "@babel/template@npm:7.16.7"
dependencies:
"@babel/code-frame": ^7.16.7
"@babel/parser": ^7.16.7
"@babel/types": ^7.16.7
checksum: 10cd112e89276e00f8b11b55a51c8b2f1262c318283a980f4d6cdb0286dc05734b9aaeeb9f3ad3311900b09bc913e02343fcaa9d4a4f413964aaab04eb84ac4a
languageName: node
linkType: hard

"@babel/traverse@npm:^7.0.0, @babel/traverse@npm:^7.1.0, @babel/traverse@npm:^7.12.11, @babel/traverse@npm:^7.12.9, @babel/traverse@npm:^7.13.0, @babel/traverse@npm:^7.15.4, @babel/traverse@npm:^7.16.0, @babel/traverse@npm:^7.16.3, @babel/traverse@npm:^7.7.2, @babel/traverse@npm:^7.9.0":
version: 7.16.3
resolution: "@babel/traverse@npm:7.16.3"
Expand All @@ -2477,6 +2623,24 @@ __metadata:
languageName: node
linkType: hard

"@babel/traverse@npm:^7.16.7":
version: 7.17.0
resolution: "@babel/traverse@npm:7.17.0"
dependencies:
"@babel/code-frame": ^7.16.7
"@babel/generator": ^7.17.0
"@babel/helper-environment-visitor": ^7.16.7
"@babel/helper-function-name": ^7.16.7
"@babel/helper-hoist-variables": ^7.16.7
"@babel/helper-split-export-declaration": ^7.16.7
"@babel/parser": ^7.17.0
"@babel/types": ^7.17.0
debug: ^4.1.0
globals: ^11.1.0
checksum: 9b7de053d8a29453fd7b9614a028d8dc811817f02948eaee02093274b67927a1cfb0513b521bc4a9328c9b6e5b021fd343b358c3526bbb6ee61ec078d4110c0c
languageName: node
linkType: hard

"@babel/types@npm:^7.0.0, @babel/types@npm:^7.12.11, @babel/types@npm:^7.12.13, @babel/types@npm:^7.12.17, @babel/types@npm:^7.12.7, @babel/types@npm:^7.15.4, @babel/types@npm:^7.15.6, @babel/types@npm:^7.16.0, @babel/types@npm:^7.3.0, @babel/types@npm:^7.3.3, @babel/types@npm:^7.4.4, @babel/types@npm:^7.8.3, @babel/types@npm:^7.9.0":
version: 7.16.0
resolution: "@babel/types@npm:7.16.0"
Expand All @@ -2487,6 +2651,16 @@ __metadata:
languageName: node
linkType: hard

"@babel/types@npm:^7.16.7, @babel/types@npm:^7.17.0":
version: 7.17.0
resolution: "@babel/types@npm:7.17.0"
dependencies:
"@babel/helper-validator-identifier": ^7.16.7
to-fast-properties: ^2.0.0
checksum: 12e5a287986fe557188e87b2c5202223f1dc83d9239a196ab936fdb9f8c1eb0be717ff19f934b5fad4e29a75586d5798f74bed209bccea1c20376b9952056f0e
languageName: node
linkType: hard

"@bcoe/v8-coverage@npm:^0.2.3":
version: 0.2.3
resolution: "@bcoe/v8-coverage@npm:0.2.3"
Expand Down Expand Up @@ -7645,6 +7819,7 @@ __metadata:
"@babel/eslint-plugin": ^7.11.3
"@babel/plugin-proposal-nullish-coalescing-operator": ^7.14.5
"@babel/plugin-proposal-optional-chaining": ^7.16.0
"@babel/plugin-transform-modules-commonjs": ^7.16.8
"@babel/plugin-transform-react-jsx": ^7.10.4
"@babel/preset-env": ^7.14.7
"@babel/register": ^7.10.5
Expand Down

0 comments on commit a73869a

Please sign in to comment.