Skip to content

Commit c84cf83

Browse files
committed
fix: Worker filename in cjs/mjs builds
1 parent 528a99f commit c84cf83

File tree

5 files changed

+17
-12
lines changed

5 files changed

+17
-12
lines changed

.circleci/config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ jobs:
1919
command: pnpm install --frozen-lockfile
2020
- run:
2121
name: build
22-
command: ASTX_WORKERS=1 pnpm prepublishOnly
22+
command: pnpm prepublishOnly
2323
- run:
2424
name: upload test coverage
2525
command: pnpm codecov
2626
- run:
2727
name: release
28-
command: ASTX_WORKERS=1 pnpm semantic-release
28+
command: pnpm semantic-release
2929
workflows:
3030
version: 2
3131
build:

convertCjsBuild.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { TransformOptions } from './src'
2+
3+
export async function astx({ astx }: TransformOptions): Promise<void> {
4+
astx.find`require.resolve('$source')`().replace(
5+
({ $source }) =>
6+
`require.resolve('${$source.stringValue.replace(/\.babel\.js$/, '.js')}')`
7+
)
8+
}

convertImportsToMjs.ts renamed to convertMjsBuild.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export async function astx({ astx, file }: TransformOptions): Promise<void> {
7171
astx.find`new Worker(require.resolve('$source'))`().replace(
7272
({ $source }) =>
7373
`new Worker(new URL('${$source.stringValue.replace(
74-
/\.js$/,
74+
/\.babel\.js$/,
7575
'.mjs'
7676
)}', import.meta.url))`
7777
)

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
],
3131
"astx": {
3232
"parser": "babel",
33-
"workers": 0
33+
"workers": 1
3434
},
3535
"main": "./cjs/index.js",
3636
"types": "./types/index.d.ts",
@@ -46,10 +46,10 @@
4646
"clean": "rimraf mjs cjs types",
4747
"build": "npm run clean && npm run build:types && npm run build:cjs && npm run check:cjs && npm run build:mjs && npm run check:mjs",
4848
"build:types": "tsc -p tsconfig.build.json && mkdir -p cjs && copy 'src/**/*.js.flow' cjs && mkdir -p mjs && copy 'src/**/*.js.flow' mjs",
49-
"build:cjs": "cross-env BABEL_ENV=es5 babel src --out-dir cjs --extensions .ts",
50-
"check:cjs": "node cjs/index.js && node cjs/node/index.js && node cjs/cli/index.js -f 'export type TransformOptions = $T' src",
51-
"build:mjs": "cross-env OUTPUT_ESM=1 babel src --out-dir mjs --out-file-extension .mjs --extensions .ts --source-maps inline && babel-node --extensions .ts src/cli/index.ts -t convertImportsToMjs.ts --parser babel --workers 0 --no-gitignore -y 'mjs/**/*.mjs'",
52-
"check:mjs": "node mjs/index.mjs && node mjs/node/index.mjs && node mjs/cli/index.mjs -f 'export type TransformOptions = $T' src",
49+
"build:cjs": "cross-env BABEL_ENV=es5 babel src --out-dir cjs --extensions .ts && babel-node --extensions .ts src/cli/index.ts -t convertCjsBuild.ts --parser babel --no-gitignore -y cjs",
50+
"check:cjs": "node cjs/cli/index.js -f 'export type TransformOptions = $T' src",
51+
"build:mjs": "cross-env OUTPUT_ESM=1 babel src --out-dir mjs --out-file-extension .mjs --extensions .ts --source-maps inline && babel-node --extensions .ts src/cli/index.ts -t convertMjsBuild.ts --parser babel --no-gitignore -y mjs",
52+
"check:mjs": "node mjs/cli/index.mjs -f 'export type TransformOptions = $T' src",
5353
"test": "cross-env NODE_ENV=test BABEL_ENV=coverage nyc --reporter=lcov --reporter=text mocha $npm_package_config_mocha",
5454
"test:watch": "cross-env NODE_ENV=test BABEL_ENV=test mocha $npm_package_config_mocha --watch",
5555
"test:debug": "cross-env NODE_ENV=test BABEL_ENV=test mocha --inspect-brk $npm_package_config_mocha",

src/node/AstxWorker.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@ export default class AstxWorker {
2727

2828
private startWorker() {
2929
if (this.ended) return
30-
const worker =
31-
typeof __filename !== 'undefined' && __filename.endsWith('.ts')
32-
? new Worker(require.resolve('./AstxWorkerEntry.babel.js'))
33-
: new Worker(require.resolve('./AstxWorkerEntry.js'))
30+
const worker = new Worker(require.resolve('./AstxWorkerEntry.babel.js'))
3431
this.worker = worker
3532
worker.once('exit', async () => {
3633
this.worker = undefined

0 commit comments

Comments
 (0)