requirejs-esm 4.2.0 → 4.4.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/LICENSE +1 -1
- package/README.md +14 -1
- package/bin/esm2requirejs.js +10 -4
- package/dist/api.js +212 -126
- package/dist/api.js.map +1 -1
- package/dist/plugin.js +215 -123
- package/dist/plugin.js.map +1 -1
- package/package.json +10 -12
- package/src/api.d.ts +3 -0
- package/src/api.js +6 -1
- package/src/fetch-text.js +1 -1
- package/src/plugin.js +8 -1
- package/src/resolve-path.js +1 -1
- package/src/transform.js +16 -2
- package/src/transformer/comments.js +16 -0
- package/src/transformer/converters.js +2 -4
- package/src/transformer/esm.js +56 -36
- package/src/transformer/index.js +3 -3
- package/src/write-text.js +2 -2
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -123,9 +123,14 @@ The `esm` plugin supports configuration with the following defaults:
|
|
|
123
123
|
mixedAmdAndEsm: false,
|
|
124
124
|
// Suppress transpiling even if an optimized module has not been loaded yet.
|
|
125
125
|
onlyAmd: false,
|
|
126
|
+
// Assume AMD/UMD if there're no import or export statements.
|
|
127
|
+
skipIfNoImportExport: false,
|
|
126
128
|
// Do not insert `"use strict"` expression to the AMD modules. You'd set it
|
|
127
129
|
// to `false` if your bundler inserts `"use strict"` to the outer scope.
|
|
128
130
|
useStrict: true,
|
|
131
|
+
// Split `export default class A {}` to `class A {}; export default A`
|
|
132
|
+
// to trade easier AST manipulation for 100% code compatibility.
|
|
133
|
+
splitDefaultNamedDeclarations: false,
|
|
129
134
|
// Enable source maps, can be an object with booleans { inline, content }.
|
|
130
135
|
// If set to true, the object will be set to { inline: true, content: true }.
|
|
131
136
|
sourceMap: false,
|
|
@@ -182,13 +187,21 @@ The returned object:
|
|
|
182
187
|
}
|
|
183
188
|
```
|
|
184
189
|
|
|
190
|
+
## Skipping and Forcing Transformation
|
|
191
|
+
|
|
192
|
+
If the option `skipIfNoImportExport` of `transform` is set to `true` and the input source contains neither `import` nor `export` statements, the input source won't be enclosed in the AMD wrapper. The input will be assumed to be in AMD/UMD format already.
|
|
193
|
+
|
|
194
|
+
If the input source contains a line "// requirejs-esm-skip-file" among the first 10 lines shorter than 100 characters, the input file will not be transformed.
|
|
195
|
+
|
|
196
|
+
If the input source contains a line "// requirejs-esm-process-file" among the first 10 lines shorter than 100 characters and the `transform` option `skipIfNoImportExport` is set to `true`, the input will be transformed nevertheless. The comment has a higher priority than the option.
|
|
197
|
+
|
|
185
198
|
## Contributing
|
|
186
199
|
|
|
187
200
|
In lieu of a formal styleguide, take care to maintain the existing coding style. Lint and test your code.
|
|
188
201
|
|
|
189
202
|
## License
|
|
190
203
|
|
|
191
|
-
Copyright (c) 2022-
|
|
204
|
+
Copyright (c) 2022-2026 Ferdinand Prantl
|
|
192
205
|
|
|
193
206
|
Licensed under the MIT license.
|
|
194
207
|
|
package/bin/esm2requirejs.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// Require module dependencies.
|
|
4
4
|
const { Command } = require('commander')
|
|
5
5
|
const glob = require('tiny-glob')
|
|
6
|
-
const { readFile, writeFile } = require('fs/promises')
|
|
6
|
+
const { readFile, writeFile } = require('node:fs/promises')
|
|
7
7
|
const { transform } = require('../dist/api')
|
|
8
8
|
|
|
9
9
|
// Define the command-line interface.
|
|
@@ -16,9 +16,11 @@ program.description('Transforms an ESM module to AMD or adapts an AMD module for
|
|
|
16
16
|
.option('-o, --output <file>', 'write the adapted module source to a file')
|
|
17
17
|
.option('-r, --rewrite', 'rewrite the input files with the adapted output')
|
|
18
18
|
.option('-s, --source-map', 'write inline source maps to the adapted output')
|
|
19
|
+
.option('-a, --skip-if-no-import-export', 'assume AMD/UMD if there\'re no import or export statements')
|
|
20
|
+
.option('-d, --split-default-named-declarations', 'split default named export to declaration and export')
|
|
19
21
|
.option('-v, --verbose', 'print progress and call stack in case of error')
|
|
20
22
|
.argument('[files...]')
|
|
21
|
-
.on('--help',
|
|
23
|
+
.on('--help', () => {
|
|
22
24
|
console.log()
|
|
23
25
|
console.log('You can use one or more file names or one or more glob patterns to specify one')
|
|
24
26
|
console.log('or more files. If you set the plugin name to an empty string, modules already')
|
|
@@ -35,6 +37,8 @@ const {
|
|
|
35
37
|
/*ecma: ecmaVersion,*/
|
|
36
38
|
plugin: pluginName,
|
|
37
39
|
sourceMap,
|
|
40
|
+
skipIfNoImportExport,
|
|
41
|
+
splitDefaultNamedDeclarations,
|
|
38
42
|
output: outputFile,
|
|
39
43
|
rewrite,
|
|
40
44
|
verbose
|
|
@@ -45,7 +49,7 @@ if (!args.length) {
|
|
|
45
49
|
}
|
|
46
50
|
|
|
47
51
|
// Main entry point.
|
|
48
|
-
(async
|
|
52
|
+
((async () => {
|
|
49
53
|
try {
|
|
50
54
|
const files = (await Promise.all(args.map(arg => glob(arg)))).flat()
|
|
51
55
|
if (!files.length) {
|
|
@@ -57,6 +61,8 @@ if (!args.length) {
|
|
|
57
61
|
/*ecmaVersion,*/
|
|
58
62
|
pluginName,
|
|
59
63
|
sourceMap,
|
|
64
|
+
skipIfNoImportExport,
|
|
65
|
+
splitDefaultNamedDeclarations,
|
|
60
66
|
verbose
|
|
61
67
|
})
|
|
62
68
|
if (updated) {
|
|
@@ -75,4 +81,4 @@ if (!args.length) {
|
|
|
75
81
|
console.error((!verbose && error.message) || error)
|
|
76
82
|
process.exitCode = 1
|
|
77
83
|
}
|
|
78
|
-
}())
|
|
84
|
+
})())
|