requirejs-esm 3.1.1 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/dist/api.js +9401 -269
- package/dist/api.js.map +1 -1
- package/dist/plugin.js +9398 -262
- package/dist/plugin.js.map +1 -1
- package/package.json +12 -13
- package/src/api.d.ts +12 -4
- package/src/plugin.js +4 -0
- package/src/transform.js +6 -1
- package/src/transformer/esm.js +13 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "requirejs-esm",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "A RequireJS plugin converting JavaScript modules from ESM to AMD.",
|
|
5
5
|
"author": "Ferdinand Prantl <prantlf@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -33,7 +33,6 @@
|
|
|
33
33
|
"src"
|
|
34
34
|
],
|
|
35
35
|
"scripts": {
|
|
36
|
-
"prepare": "npm run build && npm run demo",
|
|
37
36
|
"build": "node build",
|
|
38
37
|
"demo": "npm run demo:extern && npm run demo:local",
|
|
39
38
|
"demo:extern": "npm run optimize:extern && npm run minify:extern",
|
|
@@ -69,30 +68,30 @@
|
|
|
69
68
|
"statements": 45
|
|
70
69
|
},
|
|
71
70
|
"dependencies": {
|
|
72
|
-
"@prantlf/convert-source-map": "^
|
|
71
|
+
"@prantlf/convert-source-map": "^3.0.2",
|
|
73
72
|
"astring": "^1.9.0",
|
|
74
|
-
"charcodes": "^0.2.
|
|
75
|
-
"commander": "^
|
|
76
|
-
"meriyah": "^6.
|
|
73
|
+
"charcodes": "^0.2.1",
|
|
74
|
+
"commander": "^14.0.2",
|
|
75
|
+
"meriyah": "^6.1.4",
|
|
77
76
|
"punycode": "^2.3.1",
|
|
78
77
|
"source-map": "^0.8.0-beta.0",
|
|
79
78
|
"tiny-glob": "^0.2.9"
|
|
80
79
|
},
|
|
81
80
|
"devDependencies": {
|
|
82
|
-
"@eslint/js": "^9.
|
|
81
|
+
"@eslint/js": "^9.39.1",
|
|
83
82
|
"@prantlf/requirejs": "^3.3.1",
|
|
84
|
-
"@rollup/plugin-commonjs": "^
|
|
83
|
+
"@rollup/plugin-commonjs": "^29.0.0",
|
|
85
84
|
"@rollup/plugin-json": "^6.1.0",
|
|
86
|
-
"@rollup/plugin-node-resolve": "^16.0.
|
|
85
|
+
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
87
86
|
"c8": "^10.1.3",
|
|
88
|
-
"eslint": "^9.
|
|
89
|
-
"globals": "^16.
|
|
87
|
+
"eslint": "^9.39.1",
|
|
88
|
+
"globals": "^16.5.0",
|
|
90
89
|
"lit-html": "^1",
|
|
91
|
-
"rollup": "^4.
|
|
90
|
+
"rollup": "^4.53.1",
|
|
92
91
|
"tehanu": "^1.0.1",
|
|
93
92
|
"tehanu-repo-coco": "^1.0.1",
|
|
94
93
|
"tehanu-teru": "^1.0.1",
|
|
95
|
-
"terser": "^5.
|
|
94
|
+
"terser": "^5.44.1"
|
|
96
95
|
},
|
|
97
96
|
"keywords": [
|
|
98
97
|
"requirejs-plugin",
|
package/src/api.d.ts
CHANGED
|
@@ -9,11 +9,19 @@ declare function resolvePath(sourcePath: string, currentFile: string, options?:
|
|
|
9
9
|
|
|
10
10
|
type ResolvePath = ((sourcePath: string, currentFile: string, options?: ResolveOptions) => string) | false
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
pluginName?: string /*= 'esm''
|
|
14
|
-
|
|
12
|
+
interface TransformAstOptions {
|
|
13
|
+
pluginName?: string /*= 'esm'' */
|
|
14
|
+
resolvePath?: ResolvePath
|
|
15
|
+
useStrict?: boolean /*= true */
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface TransformOptions extends TransformAstOptions {
|
|
19
|
+
sourceMap?: boolean /*= true */
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
declare function transform(contents: string, path: string, options?: TransformOptions): string
|
|
15
23
|
|
|
16
|
-
declare function transformAst(ast: object): { amd?: true, updated?: true }
|
|
24
|
+
declare function transformAst(ast: object, options?: TransformOptions): { amd?: true, updated?: true }
|
|
17
25
|
|
|
18
26
|
declare function detectDefinesOrRequires(ast: object): {
|
|
19
27
|
namespace?: object
|
package/src/plugin.js
CHANGED
|
@@ -20,6 +20,9 @@ const {
|
|
|
20
20
|
// name with `esm!`, above all.
|
|
21
21
|
resolvePath,
|
|
22
22
|
// ecmaVersion,
|
|
23
|
+
// Do not insert `"use strict"` expression to the AMD modules. You'd set it
|
|
24
|
+
// to `false` if your bundler inserts `"use strict"` to the outer scope.
|
|
25
|
+
useStrict,
|
|
23
26
|
// Boolean or object with booleans { inline, content }.
|
|
24
27
|
sourceMap,
|
|
25
28
|
// Enable console logging.
|
|
@@ -102,6 +105,7 @@ export default {
|
|
|
102
105
|
pluginName,
|
|
103
106
|
resolvePath,
|
|
104
107
|
/*ecmaVersion,*/
|
|
108
|
+
useStrict,
|
|
105
109
|
// Always produce the source maps when transpiling in the browser, otherwise
|
|
106
110
|
// the debugging would me impossible. When building and bundling, check if
|
|
107
111
|
// the source maps were enabled for the output.
|
package/src/transform.js
CHANGED
|
@@ -13,12 +13,17 @@ export default function transform(text, file, {
|
|
|
13
13
|
// name with `esm!`, above all.
|
|
14
14
|
resolvePath = originalResolvePath,
|
|
15
15
|
// ecmaVersion = 2020,
|
|
16
|
+
// Do not insert `"use strict"` expression to the AMD modules. You'd set it
|
|
17
|
+
// to `false` if your bundler inserts `"use strict"` to the outer scope.
|
|
18
|
+
useStrict,
|
|
19
|
+
// Enable source maps, can be an object with booleans { inline, content }.
|
|
20
|
+
// If set to true, the object will be set to { inline: true, content: true }.
|
|
16
21
|
sourceMap
|
|
17
22
|
} = {}) {
|
|
18
23
|
// const ast = parse(text, { ecmaVersion, sourceType: 'module', locations: true })
|
|
19
24
|
let ast = parseModule(text, { next: true, loc: true })
|
|
20
25
|
|
|
21
|
-
const options = { sourceFileName: file, pluginName, resolvePath, originalResolvePath }
|
|
26
|
+
const options = { sourceFileName: file, pluginName, resolvePath, originalResolvePath, useStrict }
|
|
22
27
|
const { updated } = transformAst(ast, options)
|
|
23
28
|
|
|
24
29
|
let code, map
|
package/src/transformer/esm.js
CHANGED
|
@@ -2,7 +2,8 @@ import { isAnonymousImport, isImportDefault, isImportAllAs } from './validators'
|
|
|
2
2
|
import {
|
|
3
3
|
identifier, memberExpression, objectExpression, arrayExpression, blockStatement,
|
|
4
4
|
variableDeclaration, variableDeclarator, returnStatement, expressionStatement,
|
|
5
|
-
forInStatement, assignmentExpression, callExpression, functionExpression
|
|
5
|
+
forInStatement, assignmentExpression, callExpression, functionExpression,
|
|
6
|
+
literal
|
|
6
7
|
} from './factories'
|
|
7
8
|
import { toExpression, replaceLiteral, exportStatement } from './converters'
|
|
8
9
|
import { generateUid, generateUidIdentifier } from './generate-id'
|
|
@@ -385,13 +386,22 @@ function exportCopyLoop(exportsVar, importVar) {
|
|
|
385
386
|
|
|
386
387
|
// Wraps a program body of statements into an AMD module.
|
|
387
388
|
function buildAmdModule(program, options, importPaths, importVars, namedImports) {
|
|
389
|
+
const body = []
|
|
390
|
+
if (options.useStrict !== false) {
|
|
391
|
+
body.push(expressionStatement(literal('use strict')))
|
|
392
|
+
}
|
|
393
|
+
if (namedImports.length) {
|
|
394
|
+
body.push(...namedImports)
|
|
395
|
+
}
|
|
396
|
+
body.push(...program.body)
|
|
397
|
+
const bodyStatement = blockStatement(body)
|
|
388
398
|
program.body = [
|
|
389
399
|
expressionStatement(callExpression(
|
|
390
400
|
identifier('define'), importPaths.length ? [
|
|
391
401
|
prepareImportPaths(importPaths, options),
|
|
392
|
-
functionExpression(importVars,
|
|
402
|
+
functionExpression(importVars, bodyStatement)
|
|
393
403
|
] : [
|
|
394
|
-
functionExpression([],
|
|
404
|
+
functionExpression([], bodyStatement)
|
|
395
405
|
]))
|
|
396
406
|
]
|
|
397
407
|
}
|