@jsenv/plugin-bundling 1.1.0 → 1.1.2
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/plugin-bundling",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -24,14 +24,14 @@
|
|
|
24
24
|
"test": "node --conditions=development ./scripts/test.mjs"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@jsenv/babel-plugins": "1.1.
|
|
27
|
+
"@jsenv/babel-plugins": "1.1.3",
|
|
28
28
|
"@jsenv/log": "3.3.3",
|
|
29
29
|
"@jsenv/url-meta": "7.0.2",
|
|
30
30
|
"@jsenv/urls": "1.2.8",
|
|
31
31
|
"@jsenv/sourcemap": "1.0.8",
|
|
32
32
|
"acorn-import-assertions": "1.8.0",
|
|
33
33
|
"lightningcss": "1.18.0",
|
|
34
|
-
"rollup": "3.
|
|
34
|
+
"rollup": "3.10.1"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
37
|
"@jsenv/core": "*"
|
|
@@ -79,6 +79,18 @@ export const bundleJsModules = async ({
|
|
|
79
79
|
...rollupInput,
|
|
80
80
|
},
|
|
81
81
|
rollupOutput: {
|
|
82
|
+
compact: context.minification,
|
|
83
|
+
minifyInternalExports: context.minification,
|
|
84
|
+
generatedCode: {
|
|
85
|
+
arrowFunctions: context.isSupportedOnCurrentClients("arrow_function"),
|
|
86
|
+
constBindings: context.isSupportedOnCurrentClients("const_bindings"),
|
|
87
|
+
objectShorthand: context.isSupportedOnCurrentClients(
|
|
88
|
+
"object_properties_shorthand",
|
|
89
|
+
),
|
|
90
|
+
reservedNamesAsProps:
|
|
91
|
+
context.isSupportedOnCurrentClients("reserved_words"),
|
|
92
|
+
symbols: context.isSupportedOnCurrentClients("symbols"),
|
|
93
|
+
},
|
|
82
94
|
...rollupOutput,
|
|
83
95
|
},
|
|
84
96
|
})
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Each @import found in css is replaced by the file content
|
|
3
|
-
* - There is no need to worry about urls (such as background-image: url())
|
|
4
|
-
* because they are absolute (file://*) and will be made relative again by jsenv build
|
|
5
|
-
* - The sourcemap are not generated but ideally they should be
|
|
6
|
-
* It can be quite challenging, see "bundle_sourcemap.js"
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { createMagicSource } from "@jsenv/sourcemap"
|
|
10
|
-
import { applyPostCss, postCssPluginUrlVisitor } from "@jsenv/ast"
|
|
11
|
-
|
|
12
|
-
import { sortByDependencies } from "./sort_by_dependencies.js"
|
|
13
|
-
|
|
14
|
-
export const bundleCss = async ({ cssUrlInfos, context }) => {
|
|
15
|
-
const bundledCssUrlInfos = {}
|
|
16
|
-
const cssBundleInfos = await performCssBundling({
|
|
17
|
-
cssEntryUrlInfos: cssUrlInfos,
|
|
18
|
-
context,
|
|
19
|
-
})
|
|
20
|
-
cssUrlInfos.forEach((cssUrlInfo) => {
|
|
21
|
-
bundledCssUrlInfos[cssUrlInfo.url] = {
|
|
22
|
-
data: {
|
|
23
|
-
bundlerName: "postcss",
|
|
24
|
-
},
|
|
25
|
-
contentType: "text/css",
|
|
26
|
-
content: cssBundleInfos[cssUrlInfo.url].bundleContent,
|
|
27
|
-
}
|
|
28
|
-
})
|
|
29
|
-
return bundledCssUrlInfos
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const performCssBundling = async ({ cssEntryUrlInfos, context }) => {
|
|
33
|
-
const cssBundleInfos = await loadCssUrls({
|
|
34
|
-
cssEntryUrlInfos,
|
|
35
|
-
context,
|
|
36
|
-
})
|
|
37
|
-
const cssUrlsSorted = sortByDependencies(cssBundleInfos)
|
|
38
|
-
cssUrlsSorted.forEach((cssUrl) => {
|
|
39
|
-
const cssBundleInfo = cssBundleInfos[cssUrl]
|
|
40
|
-
const magicSource = createMagicSource(cssBundleInfo.content)
|
|
41
|
-
cssBundleInfo.cssUrls.forEach((cssUrl) => {
|
|
42
|
-
if (cssUrl.type === "@import") {
|
|
43
|
-
magicSource.replace({
|
|
44
|
-
start: cssUrl.atRuleStart,
|
|
45
|
-
end: cssUrl.atRuleEnd,
|
|
46
|
-
replacement: cssBundleInfos[cssUrl.url].bundleContent,
|
|
47
|
-
})
|
|
48
|
-
}
|
|
49
|
-
})
|
|
50
|
-
const { content } = magicSource.toContentAndSourcemap()
|
|
51
|
-
cssBundleInfo.bundleContent = content.trim()
|
|
52
|
-
})
|
|
53
|
-
return cssBundleInfos
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const parseCssUrls = async ({ css, url }) => {
|
|
57
|
-
const cssUrls = []
|
|
58
|
-
await applyPostCss({
|
|
59
|
-
sourcemaps: false,
|
|
60
|
-
plugins: [
|
|
61
|
-
postCssPluginUrlVisitor({
|
|
62
|
-
urlVisitor: ({
|
|
63
|
-
type,
|
|
64
|
-
specifier,
|
|
65
|
-
specifierStart,
|
|
66
|
-
specifierEnd,
|
|
67
|
-
atRuleStart,
|
|
68
|
-
atRuleEnd,
|
|
69
|
-
}) => {
|
|
70
|
-
cssUrls.push({
|
|
71
|
-
type,
|
|
72
|
-
url: new URL(specifier, url).href,
|
|
73
|
-
specifierStart,
|
|
74
|
-
specifierEnd,
|
|
75
|
-
atRuleStart,
|
|
76
|
-
atRuleEnd,
|
|
77
|
-
})
|
|
78
|
-
},
|
|
79
|
-
}),
|
|
80
|
-
],
|
|
81
|
-
url,
|
|
82
|
-
content: css,
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
return cssUrls
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const loadCssUrls = async ({ cssEntryUrlInfos, context }) => {
|
|
89
|
-
const cssBundleInfos = {}
|
|
90
|
-
const promises = []
|
|
91
|
-
const promiseMap = new Map()
|
|
92
|
-
|
|
93
|
-
const load = (cssUrlInfo) => {
|
|
94
|
-
const promiseFromData = promiseMap.get(cssUrlInfo.url)
|
|
95
|
-
if (promiseFromData) return promiseFromData
|
|
96
|
-
const promise = _load(cssUrlInfo)
|
|
97
|
-
promises.push(promise)
|
|
98
|
-
promiseMap.set(cssUrlInfo.url, promise)
|
|
99
|
-
return promise
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const _load = async (cssUrlInfo) => {
|
|
103
|
-
const cssUrls = await parseCssUrls({
|
|
104
|
-
css: cssUrlInfo.content,
|
|
105
|
-
url: cssUrlInfo.url,
|
|
106
|
-
})
|
|
107
|
-
const cssBundleInfo = {
|
|
108
|
-
content: cssUrlInfo.content,
|
|
109
|
-
cssUrls,
|
|
110
|
-
dependencies: [],
|
|
111
|
-
}
|
|
112
|
-
cssBundleInfos[cssUrlInfo.url] = cssBundleInfo
|
|
113
|
-
cssUrls.forEach((cssUrl) => {
|
|
114
|
-
if (cssUrl.type === "@import") {
|
|
115
|
-
cssBundleInfo.dependencies.push(cssUrl.url)
|
|
116
|
-
const importedCssUrlInfo = context.urlGraph.getUrlInfo(cssUrl.url)
|
|
117
|
-
load(importedCssUrlInfo)
|
|
118
|
-
}
|
|
119
|
-
})
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
cssEntryUrlInfos.forEach((cssEntryUrlInfo) => {
|
|
123
|
-
load(cssEntryUrlInfo)
|
|
124
|
-
})
|
|
125
|
-
|
|
126
|
-
const waitAll = async () => {
|
|
127
|
-
if (promises.length === 0) {
|
|
128
|
-
return
|
|
129
|
-
}
|
|
130
|
-
const promisesToWait = promises.slice()
|
|
131
|
-
promises.length = 0
|
|
132
|
-
await Promise.all(promisesToWait)
|
|
133
|
-
await waitAll()
|
|
134
|
-
}
|
|
135
|
-
await waitAll()
|
|
136
|
-
promiseMap.clear()
|
|
137
|
-
|
|
138
|
-
return cssBundleInfos
|
|
139
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
export const sortByDependencies = (nodes) => {
|
|
2
|
-
const visited = []
|
|
3
|
-
const sorted = []
|
|
4
|
-
const circular = []
|
|
5
|
-
const visit = (url) => {
|
|
6
|
-
const isSorted = sorted.includes(url)
|
|
7
|
-
if (isSorted) {
|
|
8
|
-
return
|
|
9
|
-
}
|
|
10
|
-
const isVisited = visited.includes(url)
|
|
11
|
-
if (isVisited) {
|
|
12
|
-
if (!circular.includes(url)) {
|
|
13
|
-
circular.push(url)
|
|
14
|
-
}
|
|
15
|
-
} else {
|
|
16
|
-
visited.push(url)
|
|
17
|
-
nodes[url].dependencies.forEach((dependencyUrl) => {
|
|
18
|
-
visit(dependencyUrl, url)
|
|
19
|
-
})
|
|
20
|
-
sorted.push(url)
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
Object.keys(nodes).forEach((url) => {
|
|
24
|
-
visit(url)
|
|
25
|
-
})
|
|
26
|
-
sorted.circular = circular
|
|
27
|
-
return sorted
|
|
28
|
-
}
|