requirejs-esm 1.1.0 → 2.1.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 +4 -0
- package/bin/esm2requirejs.js +10 -6
- package/dist/api.js +1 -1
- package/dist/api.js.map +1 -1
- package/dist/plugin.js +1 -1
- package/dist/plugin.js.map +1 -1
- package/package.json +23 -27
- package/src/api.d.ts +14 -0
- package/src/api.js +2 -0
- package/src/fetch-text.js +35 -0
- package/src/plugin.js +147 -0
- package/src/resolve-path.js +80 -0
- package/src/skip-module.js +18 -0
- package/src/transform.js +47 -0
- package/src/transformer/amd.js +98 -0
- package/src/transformer/converters.js +102 -0
- package/src/transformer/esm.js +295 -0
- package/src/transformer/factories.js +55 -0
- package/src/transformer/generate-id.js +96 -0
- package/src/transformer/identifier.js +75 -0
- package/src/transformer/index.js +18 -0
- package/src/transformer/keywords.js +74 -0
- package/src/transformer/validators.js +29 -0
- package/src/write-text.js +16 -0
package/README.md
CHANGED
|
@@ -8,6 +8,8 @@ A [RequireJS] plugin converting JavaScript modules from ESM to AMD. It takes car
|
|
|
8
8
|
|
|
9
9
|
The official [RequireJS optimizer] (`r.js`) does not wire up source maps from the original (not transpiled) sources to the source map of the output bundle. It makes this or similar plugins unfeasible for serious work. If you want the proper support for source maps, replace the official optimizer package ([`requirejs`]) with the forked [`@prantlf/requirejs`], which is fixed.
|
|
10
10
|
|
|
11
|
+
An alternative to this plugin is a preprocessor, which converts the module format before RequireJS consumes it. It is a lot less intrusive solution, but it requires a pluggable development web server, so that a plugin (compatible with [connect middleware]) can be registered in it. See [requirejs-esm-preprocessor] for more information.
|
|
12
|
+
|
|
11
13
|
## Installation
|
|
12
14
|
|
|
13
15
|
This module can be installed in your project using [NPM], [PNPM] or [Yarn]. Make sure, that you use [Node.js] version 14 or newer.
|
|
@@ -182,6 +184,8 @@ Licensed under the MIT license.
|
|
|
182
184
|
[RequireJS]: http://requirejs.org
|
|
183
185
|
[RequireJS optimizer]: https://requirejs.org/docs/optimization.html
|
|
184
186
|
[requirejs-babel7]: https://www.npmjs.com/package/requirejs-babel7
|
|
187
|
+
[requirejs-esm-preprocessor]: https://www.npmjs.com/package/requirejs-esm-preprocessor
|
|
188
|
+
[connect middleware]: https://github.com/senchalabs/connect/wiki
|
|
185
189
|
[`requirejs`]: https://www.npmjs.com/package/requirejs
|
|
186
190
|
[`@prantlf/requirejs`]: https://www.npmjs.com/package/@prantlf/requirejs
|
|
187
191
|
[Node.js]: http://nodejs.org/
|
package/bin/esm2requirejs.js
CHANGED
|
@@ -51,18 +51,22 @@ if (!args.length) {
|
|
|
51
51
|
}
|
|
52
52
|
for (const file of files) {
|
|
53
53
|
const text = await readFile(file, 'utf8')
|
|
54
|
-
const code = transform(text, file, {
|
|
54
|
+
const { code, updated } = transform(text, file, {
|
|
55
55
|
/*ecmaVersion,*/
|
|
56
56
|
pluginName,
|
|
57
57
|
sourceMap,
|
|
58
58
|
verbose
|
|
59
59
|
})
|
|
60
|
-
if (
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
60
|
+
if (updated) {
|
|
61
|
+
if (outputFile) {
|
|
62
|
+
await writeFile(outputFile, code)
|
|
63
|
+
} else if (rewrite) {
|
|
64
|
+
await writeFile(file, code)
|
|
65
|
+
} else {
|
|
66
|
+
console.log(`// ${file}\n\n${code}`)
|
|
67
|
+
}
|
|
64
68
|
} else {
|
|
65
|
-
console.log(`// ${file}\n\
|
|
69
|
+
console.log(`// ${file}\n\nnot updated`)
|
|
66
70
|
}
|
|
67
71
|
}
|
|
68
72
|
} catch (error) {
|
package/dist/api.js
CHANGED
|
@@ -85616,7 +85616,7 @@
|
|
|
85616
85616
|
sourceMap
|
|
85617
85617
|
} = {}) {
|
|
85618
85618
|
// const ast = parse(text, { ecmaVersion, sourceType: 'module', locations: true })
|
|
85619
|
-
let ast = parseModule(text, { loc: true });
|
|
85619
|
+
let ast = parseModule(text, { next: true, loc: true });
|
|
85620
85620
|
|
|
85621
85621
|
const options = { sourceFileName: file, pluginName, resolvePath: resolvePath$1, originalResolvePath: resolvePath };
|
|
85622
85622
|
transformModules(ast, options);
|