@jsenv/core 30.1.0 → 30.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/main.js +24 -23
- package/package.json +2 -2
- package/src/build/line_break_unix.js +26 -0
- package/src/build/version_generator.js +2 -28
package/dist/main.js
CHANGED
|
@@ -20361,36 +20361,16 @@ ${globalName}.__v__ = function (specifier) {
|
|
|
20361
20361
|
`;
|
|
20362
20362
|
};
|
|
20363
20363
|
|
|
20364
|
-
|
|
20365
|
-
// https://github.com/rollup/rollup/blob/5a5391971d695c808eed0c5d7d2c6ccb594fc689/src/Chunk.ts#L870
|
|
20366
|
-
const createVersionGenerator = () => {
|
|
20367
|
-
const hash = createHash("sha256");
|
|
20368
|
-
return {
|
|
20369
|
-
augmentWithContent: ({
|
|
20370
|
-
content,
|
|
20371
|
-
contentType = "application/octet-stream",
|
|
20372
|
-
lineBreakNormalization = false
|
|
20373
|
-
}) => {
|
|
20374
|
-
hash.update(lineBreakNormalization && CONTENT_TYPE.isTextual(contentType) ? normalizeLineBreaks(content) : content);
|
|
20375
|
-
},
|
|
20376
|
-
augment: value => {
|
|
20377
|
-
hash.update(value);
|
|
20378
|
-
},
|
|
20379
|
-
generate: () => {
|
|
20380
|
-
return hash.digest("hex").slice(0, 8);
|
|
20381
|
-
}
|
|
20382
|
-
};
|
|
20383
|
-
};
|
|
20384
|
-
const normalizeLineBreaks = stringOrBuffer => {
|
|
20364
|
+
const ensureUnixLineBreaks = stringOrBuffer => {
|
|
20385
20365
|
if (typeof stringOrBuffer === "string") {
|
|
20386
20366
|
const stringWithLinuxBreaks = stringOrBuffer.replace(/\r\n/g, "\n");
|
|
20387
20367
|
return stringWithLinuxBreaks;
|
|
20388
20368
|
}
|
|
20389
|
-
return
|
|
20369
|
+
return ensureUnixLineBreaksOnBuffer(stringOrBuffer);
|
|
20390
20370
|
};
|
|
20391
20371
|
|
|
20392
20372
|
// https://github.com/nodejs/help/issues/1738#issuecomment-458460503
|
|
20393
|
-
const
|
|
20373
|
+
const ensureUnixLineBreaksOnBuffer = buffer => {
|
|
20394
20374
|
const int32Array = new Int32Array(buffer, 0, buffer.length);
|
|
20395
20375
|
const int32ArrayWithLineBreaksNormalized = int32Array.filter((element, index, typedArray) => {
|
|
20396
20376
|
if (element === 0x0d) {
|
|
@@ -20406,6 +20386,27 @@ const normalizeLineBreaksForBuffer = buffer => {
|
|
|
20406
20386
|
return Buffer.from(int32ArrayWithLineBreaksNormalized);
|
|
20407
20387
|
};
|
|
20408
20388
|
|
|
20389
|
+
// https://github.com/rollup/rollup/blob/19e50af3099c2f627451a45a84e2fa90d20246d5/src/utils/FileEmitter.ts#L47
|
|
20390
|
+
// https://github.com/rollup/rollup/blob/5a5391971d695c808eed0c5d7d2c6ccb594fc689/src/Chunk.ts#L870
|
|
20391
|
+
const createVersionGenerator = () => {
|
|
20392
|
+
const hash = createHash("sha256");
|
|
20393
|
+
return {
|
|
20394
|
+
augmentWithContent: ({
|
|
20395
|
+
content,
|
|
20396
|
+
contentType = "application/octet-stream",
|
|
20397
|
+
lineBreakNormalization = false
|
|
20398
|
+
}) => {
|
|
20399
|
+
hash.update(lineBreakNormalization && CONTENT_TYPE.isTextual(contentType) ? ensureUnixLineBreaks(content) : content);
|
|
20400
|
+
},
|
|
20401
|
+
augment: value => {
|
|
20402
|
+
hash.update(value);
|
|
20403
|
+
},
|
|
20404
|
+
generate: () => {
|
|
20405
|
+
return hash.digest("hex").slice(0, 8);
|
|
20406
|
+
}
|
|
20407
|
+
};
|
|
20408
|
+
};
|
|
20409
|
+
|
|
20409
20410
|
/*
|
|
20410
20411
|
* Build is split in 3 steps:
|
|
20411
20412
|
* 1. craft
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/core",
|
|
3
|
-
"version": "30.
|
|
3
|
+
"version": "30.2.0",
|
|
4
4
|
"description": "Tool to develop, test and build js projects",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
"@jsenv/abort": "4.2.4",
|
|
70
70
|
"@jsenv/ast": "2.0.0",
|
|
71
71
|
"@jsenv/babel-plugins": "1.1.2",
|
|
72
|
-
"@jsenv/plugin-bundling": "1.0
|
|
72
|
+
"@jsenv/plugin-bundling": "1.1.0",
|
|
73
73
|
"@jsenv/filesystem": "4.1.9",
|
|
74
74
|
"@jsenv/importmap": "1.2.1",
|
|
75
75
|
"@jsenv/integrity": "0.0.1",
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export const ensureUnixLineBreaks = (stringOrBuffer) => {
|
|
2
|
+
if (typeof stringOrBuffer === "string") {
|
|
3
|
+
const stringWithLinuxBreaks = stringOrBuffer.replace(/\r\n/g, "\n")
|
|
4
|
+
return stringWithLinuxBreaks
|
|
5
|
+
}
|
|
6
|
+
return ensureUnixLineBreaksOnBuffer(stringOrBuffer)
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// https://github.com/nodejs/help/issues/1738#issuecomment-458460503
|
|
10
|
+
const ensureUnixLineBreaksOnBuffer = (buffer) => {
|
|
11
|
+
const int32Array = new Int32Array(buffer, 0, buffer.length)
|
|
12
|
+
const int32ArrayWithLineBreaksNormalized = int32Array.filter(
|
|
13
|
+
(element, index, typedArray) => {
|
|
14
|
+
if (element === 0x0d) {
|
|
15
|
+
if (typedArray[index + 1] === 0x0a) {
|
|
16
|
+
// Windows -> Unix
|
|
17
|
+
return false
|
|
18
|
+
}
|
|
19
|
+
// Mac OS -> Unix
|
|
20
|
+
typedArray[index] = 0x0a
|
|
21
|
+
}
|
|
22
|
+
return true
|
|
23
|
+
},
|
|
24
|
+
)
|
|
25
|
+
return Buffer.from(int32ArrayWithLineBreaksNormalized)
|
|
26
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createHash } from "node:crypto"
|
|
2
2
|
|
|
3
3
|
import { CONTENT_TYPE } from "@jsenv/utils/src/content_type/content_type.js"
|
|
4
|
+
import { ensureUnixLineBreaks } from "./line_break_unix.js"
|
|
4
5
|
|
|
5
6
|
// https://github.com/rollup/rollup/blob/19e50af3099c2f627451a45a84e2fa90d20246d5/src/utils/FileEmitter.ts#L47
|
|
6
7
|
// https://github.com/rollup/rollup/blob/5a5391971d695c808eed0c5d7d2c6ccb594fc689/src/Chunk.ts#L870
|
|
@@ -15,7 +16,7 @@ export const createVersionGenerator = () => {
|
|
|
15
16
|
}) => {
|
|
16
17
|
hash.update(
|
|
17
18
|
lineBreakNormalization && CONTENT_TYPE.isTextual(contentType)
|
|
18
|
-
?
|
|
19
|
+
? ensureUnixLineBreaks(content)
|
|
19
20
|
: content,
|
|
20
21
|
)
|
|
21
22
|
},
|
|
@@ -27,30 +28,3 @@ export const createVersionGenerator = () => {
|
|
|
27
28
|
},
|
|
28
29
|
}
|
|
29
30
|
}
|
|
30
|
-
|
|
31
|
-
const normalizeLineBreaks = (stringOrBuffer) => {
|
|
32
|
-
if (typeof stringOrBuffer === "string") {
|
|
33
|
-
const stringWithLinuxBreaks = stringOrBuffer.replace(/\r\n/g, "\n")
|
|
34
|
-
return stringWithLinuxBreaks
|
|
35
|
-
}
|
|
36
|
-
return normalizeLineBreaksForBuffer(stringOrBuffer)
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// https://github.com/nodejs/help/issues/1738#issuecomment-458460503
|
|
40
|
-
const normalizeLineBreaksForBuffer = (buffer) => {
|
|
41
|
-
const int32Array = new Int32Array(buffer, 0, buffer.length)
|
|
42
|
-
const int32ArrayWithLineBreaksNormalized = int32Array.filter(
|
|
43
|
-
(element, index, typedArray) => {
|
|
44
|
-
if (element === 0x0d) {
|
|
45
|
-
if (typedArray[index + 1] === 0x0a) {
|
|
46
|
-
// Windows -> Unix
|
|
47
|
-
return false
|
|
48
|
-
}
|
|
49
|
-
// Mac OS -> Unix
|
|
50
|
-
typedArray[index] = 0x0a
|
|
51
|
-
}
|
|
52
|
-
return true
|
|
53
|
-
},
|
|
54
|
-
)
|
|
55
|
-
return Buffer.from(int32ArrayWithLineBreaksNormalized)
|
|
56
|
-
}
|