Skip to content

Commit babf6d9

Browse files
committed
feat: Insert "use strict" to output AMD code by default
BREAKING CHANGE: Each AMD module output will start with `"use strict"` by default from now on. ESM execution mode is strict by default. Comply to this in the output AMD code too. You can set the flag `useStrict` to `false` to relax the parse mode of the output AMD modules.
1 parent 99e25c9 commit babf6d9

File tree

8 files changed

+143
-462
lines changed

8 files changed

+143
-462
lines changed

.github/workflows/ci.yml

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
1-
name: Test or Release
1+
name: Test and Release
22

33
on:
4-
- push
5-
- pull_request
4+
push:
5+
branches:
6+
- master
7+
tags-ignore:
8+
- '**'
9+
paths-ignore:
10+
- '**/*.md'
11+
- LICENSE
12+
pull_request:
13+
14+
permissions:
15+
id-token: write
16+
contents: write
617

718
jobs:
8-
test-or-release:
19+
test-and-release:
920
runs-on: ubuntu-latest
1021
steps:
11-
- uses: actions/checkout@v4
22+
- uses: actions/checkout@v5
1223
- uses: pnpm/action-setup@v4
1324
with:
1425
version: latest
15-
- uses: actions/setup-node@v4
26+
- uses: actions/setup-node@v5
1627
with:
1728
node-version: 'lts/*'
1829
registry-url: 'https://registry.npmjs.org'
@@ -21,7 +32,7 @@ jobs:
2132
- run: npm test
2233
- uses: prantlf/publish-release-action@v1
2334
with:
35+
no-npm-auth: true
2436
no-archives: true
2537
env:
2638
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
27-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

CHANGELOG.md

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# Changes
2+
13
## [1.1.0](https://github.com/prantlf/karma-requirejs-esm-preprocessor/compare/v1.0.10...v1.1.0) (2025-05-14)
24

35
### Features
@@ -6,71 +8,61 @@
68

79
## [1.0.10](https://github.com/prantlf/karma-requirejs-esm-preprocessor/compare/v1.0.9...v1.0.10) (2023-05-29)
810

9-
1011
### Bug Fixes
1112

1213
* Upgrade dependencies ([c59ee28](https://github.com/prantlf/karma-requirejs-esm-preprocessor/commit/c59ee28f9641df3aaad3f08bf5bd03e45e4283c6))
1314

1415
## [1.0.9](https://github.com/prantlf/karma-requirejs-esm-preprocessor/compare/v1.0.8...v1.0.9) (2023-05-10)
1516

16-
1717
### Bug Fixes
1818

1919
* Upgrade dependencies ([c9d0251](https://github.com/prantlf/karma-requirejs-esm-preprocessor/commit/c9d025100a8096cb86fdbc41de150fdf2c251234))
2020

2121
## [1.0.8](https://github.com/prantlf/karma-requirejs-esm-preprocessor/compare/v1.0.7...v1.0.8) (2023-05-05)
2222

23-
2423
### Bug Fixes
2524

2625
* Upgrade dependencies ([8c12988](https://github.com/prantlf/karma-requirejs-esm-preprocessor/commit/8c129880030f1055f8d9491381b8470824473101))
2726

2827
## [1.0.7](https://github.com/prantlf/karma-requirejs-esm-preprocessor/compare/v1.0.6...v1.0.7) (2023-05-05)
2928

30-
3129
### Bug Fixes
3230

3331
* Upgrade dependencies ([3f8fcea](https://github.com/prantlf/karma-requirejs-esm-preprocessor/commit/3f8fcea28bfef1b5ab64b91b81ecc1a415930aa0))
3432

3533
## [1.0.6](https://github.com/prantlf/karma-requirejs-esm-preprocessor/compare/v1.0.5...v1.0.6) (2022-04-18)
3634

37-
3835
### Bug Fixes
3936

4037
* Upgrade dependencies ([bd2dd2f](https://github.com/prantlf/karma-requirejs-esm-preprocessor/commit/bd2dd2fbbbf44c78069ac67860559e0ef8b8d820))
4138

4239
## [1.0.5](https://github.com/prantlf/karma-requirejs-esm-preprocessor/compare/v1.0.4...v1.0.5) (2022-04-10)
4340

44-
4541
### Bug Fixes
4642

4743
* Base the paths passed to isScript on basePath ([9d8a93d](https://github.com/prantlf/karma-requirejs-esm-preprocessor/commit/9d8a93de095a528b493bfce51798cb76fb7b4a30))
4844
* Upgrade dependencies ([63a539b](https://github.com/prantlf/karma-requirejs-esm-preprocessor/commit/63a539b11c2bb2ea9978be62c4e0b7955a115b16))
4945

5046
## [1.0.4](https://github.com/prantlf/karma-requirejs-esm-preprocessor/compare/v1.0.3...v1.0.4) (2022-04-09)
5147

52-
5348
### Bug Fixes
5449

5550
* Upgrade dependencies ([b0391ae](https://github.com/prantlf/karma-requirejs-esm-preprocessor/commit/b0391aeefd7c090880dfca260bef7c5655141f04))
5651

5752
## [1.0.3](https://github.com/prantlf/karma-requirejs-esm-preprocessor/compare/v1.0.2...v1.0.3) (2022-04-09)
5853

59-
6054
### Bug Fixes
6155

6256
* Upgrade dependencies ([77a45ac](https://github.com/prantlf/karma-requirejs-esm-preprocessor/commit/77a45ac94c53e72fec437970ef52358cbc41756b))
6357

6458
## [1.0.2](https://github.com/prantlf/karma-requirejs-esm-preprocessor/compare/v1.0.1...v1.0.2) (2022-04-08)
6559

66-
6760
### Bug Fixes
6861

6962
* Upgrade dependencies ([2e94b65](https://github.com/prantlf/karma-requirejs-esm-preprocessor/commit/2e94b65fa888d16b0d265865db21065166b9bceb))
7063

7164
## [1.0.1](https://github.com/prantlf/karma-requirejs-esm-preprocessor/compare/v1.0.0...v1.0.1) (2022-04-04)
7265

73-
7466
### Bug Fixes
7567

7668
* Move requirejs-esm-preprocessor to peerDependencies ([2ccdfb3](https://github.com/prantlf/karma-requirejs-esm-preprocessor/commit/2ccdfb36615459decd882f5eef305d7e10f45a3d))

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
# karma-requirejs-esm-preprocessor
22

3-
[![Latest version](https://img.shields.io/npm/v/karma-requirejs-esm-preprocessor)
4-
![Dependency status](https://img.shields.io/librariesio/release/npm/karma-requirejs-esm-preprocessor)
5-
](https://www.npmjs.com/package/karma-requirejs-esm-preprocessor)
6-
73
[Karma] preprocessor for converting ES modules to AMD in [RequireJS] projects. Uses [requirejs-esm-preprocessor].
84

95
## Synopsis
@@ -38,6 +34,12 @@ isScript(path: string): boolean
3834

3935
Allows further filtering the files before passing them to the preprocessor. If the patterns are inconvenient to specify what files should be preprocessed, a simple pattern can be used to capture all files and the final filtering be done by `isScript` returning `true` only for the paths to files which need preprocessing. The default is `undefined` - no extra filtering.
4036

37+
```ts
38+
useStrict: boolean
39+
```
40+
41+
Controls inserting `"use strict"` expression to the AMD code output. ESM modules are parsed in the strict mode by default, while AMD modules need the `"use strict"` statement. You can set this flag to `false` to relax the parse mode of the output AMD modules. The default is `true`.
42+
4143
```ts
4244
sourceMap: boolean
4345
```

index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ const { preprocess } = require('requirejs-esm-preprocessor')
22

33
function createPreprocessor(args, config, helper) {
44
const { basePath, logLevel, LOG_DEBUG, LOG_DISABLE, requirejsEsmPreprocessor } = config
5-
const defaults = { sourceMap: true }
6-
const { isScript, sourceMap } = helper.merge(defaults, args, requirejsEsmPreprocessor || {})
5+
const defaults = { useStrict: true, sourceMap: true }
6+
const { isScript, useStrict, sourceMap } = helper.merge(defaults, args, requirejsEsmPreprocessor || {})
77
const verbose = logLevel === LOG_DEBUG
88
const silent = logLevel === LOG_DISABLE
99
const { length: basePathLen } = basePath
@@ -12,7 +12,7 @@ function createPreprocessor(args, config, helper) {
1212
let { originalPath: path } = file
1313
if (path.startsWith(basePath)) path = path.substring(basePathLen)
1414
if (!isScript || isScript(path)) {
15-
contents = preprocess({ path, contents, isScript, sourceMap, verbose, silent })
15+
contents = preprocess({ path, contents, isScript, useStrict, sourceMap, verbose, silent })
1616
}
1717
done(null, contents)
1818
}

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,19 @@
3737
"reporter": []
3838
},
3939
"peerDependencies": {
40-
"requirejs-esm-preprocessor": "^2.1.1"
40+
"requirejs-esm-preprocessor": "^3.0.0"
4141
},
4242
"devDependencies": {
43-
"@eslint/js": "^9.26.0",
43+
"@eslint/js": "^9.39.1",
4444
"c8": "^10.1.3",
45-
"eslint": "^9.26.0",
46-
"globals": "^16.1.0",
47-
"jasmine-core": "^5.7.1",
45+
"eslint": "^9.39.1",
46+
"globals": "^16.5.0",
47+
"jasmine-core": "^5.12.1",
4848
"karma": "^6.4.4",
4949
"karma-brief-reporter": "^0.2.2",
5050
"karma-chrome-launcher": "^3.2.0",
5151
"karma-jasmine": "^5.1.0",
52-
"requirejs-esm-preprocessor": "^2.1.1"
52+
"requirejs-esm-preprocessor": "^3.0.0"
5353
},
5454
"keywords": [
5555
"karma-preprocessor",
@@ -62,4 +62,4 @@
6262
"esm",
6363
"es6"
6464
]
65-
}
65+
}

0 commit comments

Comments
 (0)