@jsenv/ast 1.4.10 → 2.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/package.json +1 -2
- package/src/main.js +0 -1
- package/src/css/parcel_css.js +0 -58
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/ast",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Parse and transform HTML,CSS and JS",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -34,7 +34,6 @@
|
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@babel/parser": "7.20.7",
|
|
37
|
-
"@parcel/css": "1.14.0",
|
|
38
37
|
"acorn": "8.8.1",
|
|
39
38
|
"acorn-import-assertions": "1.8.0",
|
|
40
39
|
"acorn-walk": "8.2.0",
|
package/src/main.js
CHANGED
package/src/css/parcel_css.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { createRequire } from "node:module"
|
|
2
|
-
import { fileURLToPath } from "node:url"
|
|
3
|
-
|
|
4
|
-
const require = createRequire(import.meta.url)
|
|
5
|
-
|
|
6
|
-
export const transpileWithParcel = (urlInfo, context) => {
|
|
7
|
-
const css = require("@parcel/css")
|
|
8
|
-
const targets = runtimeCompatToTargets(context.runtimeCompat)
|
|
9
|
-
const { code, map } = css.transform({
|
|
10
|
-
filename: fileURLToPath(urlInfo.originalUrl),
|
|
11
|
-
code: Buffer.from(urlInfo.content),
|
|
12
|
-
targets,
|
|
13
|
-
minify: false,
|
|
14
|
-
})
|
|
15
|
-
return { code, map }
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const minifyWithParcel = (urlInfo, context) => {
|
|
19
|
-
const css = require("@parcel/css")
|
|
20
|
-
const targets = runtimeCompatToTargets(context.runtimeCompat)
|
|
21
|
-
const { code, map } = css.transform({
|
|
22
|
-
filename: fileURLToPath(urlInfo.originalUrl),
|
|
23
|
-
code: Buffer.from(urlInfo.content),
|
|
24
|
-
targets,
|
|
25
|
-
minify: true,
|
|
26
|
-
})
|
|
27
|
-
return { code, map }
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export const bundleWithParcel = (urlInfo, context) => {
|
|
31
|
-
const targets = runtimeCompatToTargets(context.runtimeCompat)
|
|
32
|
-
const css = require("@parcel/css")
|
|
33
|
-
const { code, map } = css.bundle({
|
|
34
|
-
filename: fileURLToPath(urlInfo.originalUrl),
|
|
35
|
-
targets,
|
|
36
|
-
minify: false,
|
|
37
|
-
})
|
|
38
|
-
return { code, map }
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const runtimeCompatToTargets = (runtimeCompat) => {
|
|
42
|
-
const targets = {}
|
|
43
|
-
;["chrome", "firefox", "ie", "opera", "safari"].forEach((runtimeName) => {
|
|
44
|
-
const version = runtimeCompat[runtimeName]
|
|
45
|
-
if (version) {
|
|
46
|
-
targets[runtimeName] = versionToBits(version)
|
|
47
|
-
}
|
|
48
|
-
})
|
|
49
|
-
return targets
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const versionToBits = (version) => {
|
|
53
|
-
const [major, minor = 0, patch = 0] = version
|
|
54
|
-
.split("-")[0]
|
|
55
|
-
.split(".")
|
|
56
|
-
.map((v) => parseInt(v, 10))
|
|
57
|
-
return (major << 16) | (minor << 8) | patch
|
|
58
|
-
}
|