requirejs-esm 4.1.0 → 4.2.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/dist/api.js +36 -9
- package/dist/api.js.map +1 -1
- package/dist/plugin.js +36 -9
- package/dist/plugin.js.map +1 -1
- package/package.json +1 -1
- package/src/transformer/amd.js +31 -5
- package/src/transformer/index.js +6 -5
package/package.json
CHANGED
package/src/transformer/amd.js
CHANGED
|
@@ -153,17 +153,25 @@ export function detectDefinesOrRequires(program) {
|
|
|
153
153
|
|
|
154
154
|
// Updates dependency paths to be prefixed by `esm!` or otherwise updated.
|
|
155
155
|
export function updateAmdDeps(amd, options) {
|
|
156
|
-
options.onBeforeUpdate?.(
|
|
156
|
+
let updated = options.onBeforeUpdate?.({
|
|
157
|
+
...options,
|
|
158
|
+
amd
|
|
159
|
+
})
|
|
157
160
|
|
|
158
161
|
const { deps } = amd
|
|
159
|
-
if (!deps)
|
|
162
|
+
if (!deps) {
|
|
163
|
+
afterUpdate()
|
|
164
|
+
return updated
|
|
165
|
+
}
|
|
160
166
|
|
|
161
167
|
const { sourceFileName: parentName } = options
|
|
162
168
|
const { elements } = deps
|
|
163
|
-
if (!elements.length)
|
|
169
|
+
if (!elements.length) {
|
|
170
|
+
afterUpdate()
|
|
171
|
+
return updated
|
|
172
|
+
}
|
|
164
173
|
|
|
165
174
|
const { resolvePath } = options
|
|
166
|
-
let updated
|
|
167
175
|
for (const element of elements) {
|
|
168
176
|
if (element.type === 'Literal') {
|
|
169
177
|
const moduleName = element.value
|
|
@@ -175,7 +183,25 @@ export function updateAmdDeps(amd, options) {
|
|
|
175
183
|
}
|
|
176
184
|
}
|
|
177
185
|
|
|
178
|
-
|
|
186
|
+
afterUpdate()
|
|
179
187
|
|
|
180
188
|
return updated
|
|
189
|
+
|
|
190
|
+
function afterUpdate() {
|
|
191
|
+
const updatedNow = options.onAfterUpdate?.({
|
|
192
|
+
...options,
|
|
193
|
+
amd
|
|
194
|
+
})
|
|
195
|
+
updated ||= updatedNow
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export function callAmdUpdateHooks(amd, options) {
|
|
200
|
+
options = {
|
|
201
|
+
...options,
|
|
202
|
+
amd
|
|
203
|
+
}
|
|
204
|
+
const updatedBefore = options.onBeforeUpdate?.(options)
|
|
205
|
+
const updatedAfter = options.onAfterUpdate?.(options)
|
|
206
|
+
return updatedBefore || updatedAfter
|
|
181
207
|
}
|
package/src/transformer/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { detectDefinesOrRequires, updateAmdDeps } from './amd'
|
|
1
|
+
import { detectDefinesOrRequires, updateAmdDeps, callAmdUpdateHooks } from './amd'
|
|
2
2
|
import { detectImportsAndExports, transformEsmToAmd } from './esm'
|
|
3
3
|
|
|
4
4
|
export function transformAst(program, options = {}) {
|
|
@@ -7,10 +7,11 @@ export function transformAst(program, options = {}) {
|
|
|
7
7
|
const result = {}
|
|
8
8
|
if (length) {
|
|
9
9
|
result.amd = true
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
for (const amd of amds) {
|
|
11
|
+
const updated = options.resolvePath
|
|
12
|
+
? updateAmdDeps(amd, options)
|
|
13
|
+
: callAmdUpdateHooks(amd, options)
|
|
14
|
+
result.updated ||= updated
|
|
14
15
|
}
|
|
15
16
|
} else {
|
|
16
17
|
transformEsmToAmd(program, options)
|