@jsenv/core 30.3.8 → 30.3.9

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 CHANGED
@@ -20223,6 +20223,44 @@ const getCorePlugins = ({
20223
20223
  })] : [])];
20224
20224
  };
20225
20225
 
20226
+ const ensureUnixLineBreaks = stringOrBuffer => {
20227
+ if (typeof stringOrBuffer === "string") {
20228
+ const stringWithLinuxBreaks = stringOrBuffer.replace(/\r\n/g, "\n");
20229
+ return stringWithLinuxBreaks;
20230
+ }
20231
+ return ensureUnixLineBreaksOnBuffer(stringOrBuffer);
20232
+ };
20233
+
20234
+ // https://github.com/nodejs/help/issues/1738#issuecomment-458460503
20235
+ const ensureUnixLineBreaksOnBuffer = buffer => {
20236
+ const int32Array = new Int32Array(buffer, 0, buffer.length);
20237
+ const int32ArrayWithLineBreaksNormalized = int32Array.filter((element, index, typedArray) => {
20238
+ if (element === 0x0d) {
20239
+ if (typedArray[index + 1] === 0x0a) {
20240
+ // Windows -> Unix
20241
+ return false;
20242
+ }
20243
+ // Mac OS -> Unix
20244
+ typedArray[index] = 0x0a;
20245
+ }
20246
+ return true;
20247
+ });
20248
+ return Buffer.from(int32ArrayWithLineBreaksNormalized);
20249
+ };
20250
+
20251
+ const jsenvPluginLineBreakNormalization = () => {
20252
+ return {
20253
+ name: "jsenv:line_break_normalizer",
20254
+ appliesDuring: "build",
20255
+ transformUrlContent: urlInfo => {
20256
+ if (CONTENT_TYPE.isTextual(urlInfo.contentType)) {
20257
+ return ensureUnixLineBreaks(urlInfo.content);
20258
+ }
20259
+ return null;
20260
+ }
20261
+ };
20262
+ };
20263
+
20226
20264
  const GRAPH = {
20227
20265
  map: (graph, callback) => {
20228
20266
  const array = [];
@@ -20485,42 +20523,13 @@ const injectVersionMappingsAsImportmap = async ({
20485
20523
  });
20486
20524
  };
20487
20525
 
20488
- const ensureUnixLineBreaks = stringOrBuffer => {
20489
- if (typeof stringOrBuffer === "string") {
20490
- const stringWithLinuxBreaks = stringOrBuffer.replace(/\r\n/g, "\n");
20491
- return stringWithLinuxBreaks;
20492
- }
20493
- return ensureUnixLineBreaksOnBuffer(stringOrBuffer);
20494
- };
20495
-
20496
- // https://github.com/nodejs/help/issues/1738#issuecomment-458460503
20497
- const ensureUnixLineBreaksOnBuffer = buffer => {
20498
- const int32Array = new Int32Array(buffer, 0, buffer.length);
20499
- const int32ArrayWithLineBreaksNormalized = int32Array.filter((element, index, typedArray) => {
20500
- if (element === 0x0d) {
20501
- if (typedArray[index + 1] === 0x0a) {
20502
- // Windows -> Unix
20503
- return false;
20504
- }
20505
- // Mac OS -> Unix
20506
- typedArray[index] = 0x0a;
20507
- }
20508
- return true;
20509
- });
20510
- return Buffer.from(int32ArrayWithLineBreaksNormalized);
20511
- };
20512
-
20513
20526
  // https://github.com/rollup/rollup/blob/19e50af3099c2f627451a45a84e2fa90d20246d5/src/utils/FileEmitter.ts#L47
20514
20527
  // https://github.com/rollup/rollup/blob/5a5391971d695c808eed0c5d7d2c6ccb594fc689/src/Chunk.ts#L870
20515
20528
  const createVersionGenerator = () => {
20516
20529
  const hash = createHash("sha256");
20517
20530
  return {
20518
- augmentWithContent: ({
20519
- content,
20520
- contentType = "application/octet-stream",
20521
- lineBreakNormalization = false
20522
- }) => {
20523
- hash.update(lineBreakNormalization && CONTENT_TYPE.isTextual(contentType) ? ensureUnixLineBreaks(content) : content);
20531
+ augmentWithContent: content => {
20532
+ hash.update(content);
20524
20533
  },
20525
20534
  augment: value => {
20526
20535
  hash.update(value);
@@ -20772,7 +20781,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
20772
20781
  build: true,
20773
20782
  runtimeCompat,
20774
20783
  ...contextSharedDuringBuild,
20775
- plugins: [urlAnalysisPlugin, jsenvPluginAsJsClassic({
20784
+ plugins: [urlAnalysisPlugin, ...(lineBreakNormalization ? [jsenvPluginLineBreakNormalization()] : []), jsenvPluginAsJsClassic({
20776
20785
  jsClassicLibrary: false,
20777
20786
  jsClassicFallback: true,
20778
20787
  systemJsInjection: true
@@ -21364,11 +21373,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
21364
21373
  cleanupJsenvAttributes: true
21365
21374
  }) : urlInfo.content;
21366
21375
  const contentVersionGenerator = createVersionGenerator();
21367
- contentVersionGenerator.augmentWithContent({
21368
- content: urlContent,
21369
- contentType: urlInfo.contentType,
21370
- lineBreakNormalization
21371
- });
21376
+ contentVersionGenerator.augmentWithContent(urlContent);
21372
21377
  const contentVersion = contentVersionGenerator.generate();
21373
21378
  contentVersionMap.set(urlInfo.url, contentVersion);
21374
21379
  const versionMutations = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/core",
3
- "version": "30.3.8",
3
+ "version": "30.3.9",
4
4
  "description": "Tool to develop, test and build js projects",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -67,6 +67,7 @@ import { jsenvPluginUrlAnalysis } from "../plugins/url_analysis/jsenv_plugin_url
67
67
  import { jsenvPluginInline } from "../plugins/inline/jsenv_plugin_inline.js"
68
68
  import { jsenvPluginAsJsClassic } from "../plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic.js"
69
69
  import { getCorePlugins } from "../plugins/plugins.js"
70
+ import { jsenvPluginLineBreakNormalization } from "./jsenv_plugin_line_break_normalization.js"
70
71
 
71
72
  import { GRAPH } from "./graph_utils.js"
72
73
  import { createBuildUrlsGenerator } from "./build_urls_generator.js"
@@ -333,6 +334,9 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
333
334
  ...contextSharedDuringBuild,
334
335
  plugins: [
335
336
  urlAnalysisPlugin,
337
+ ...(lineBreakNormalization
338
+ ? [jsenvPluginLineBreakNormalization()]
339
+ : []),
336
340
  jsenvPluginAsJsClassic({
337
341
  jsClassicLibrary: false,
338
342
  jsClassicFallback: true,
@@ -1017,11 +1021,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
1017
1021
  )
1018
1022
  : urlInfo.content
1019
1023
  const contentVersionGenerator = createVersionGenerator()
1020
- contentVersionGenerator.augmentWithContent({
1021
- content: urlContent,
1022
- contentType: urlInfo.contentType,
1023
- lineBreakNormalization,
1024
- })
1024
+ contentVersionGenerator.augmentWithContent(urlContent)
1025
1025
  const contentVersion = contentVersionGenerator.generate()
1026
1026
  contentVersionMap.set(urlInfo.url, contentVersion)
1027
1027
  const versionMutations = []
@@ -0,0 +1,16 @@
1
+ import { CONTENT_TYPE } from "@jsenv/utils/src/content_type/content_type.js"
2
+
3
+ import { ensureUnixLineBreaks } from "./line_break_unix.js"
4
+
5
+ export const jsenvPluginLineBreakNormalization = () => {
6
+ return {
7
+ name: "jsenv:line_break_normalizer",
8
+ appliesDuring: "build",
9
+ transformUrlContent: (urlInfo) => {
10
+ if (CONTENT_TYPE.isTextual(urlInfo.contentType)) {
11
+ return ensureUnixLineBreaks(urlInfo.content)
12
+ }
13
+ return null
14
+ },
15
+ }
16
+ }
@@ -1,24 +1,13 @@
1
1
  import { createHash } from "node:crypto"
2
2
 
3
- import { CONTENT_TYPE } from "@jsenv/utils/src/content_type/content_type.js"
4
- import { ensureUnixLineBreaks } from "./line_break_unix.js"
5
-
6
3
  // https://github.com/rollup/rollup/blob/19e50af3099c2f627451a45a84e2fa90d20246d5/src/utils/FileEmitter.ts#L47
7
4
  // https://github.com/rollup/rollup/blob/5a5391971d695c808eed0c5d7d2c6ccb594fc689/src/Chunk.ts#L870
8
5
  export const createVersionGenerator = () => {
9
6
  const hash = createHash("sha256")
10
7
 
11
8
  return {
12
- augmentWithContent: ({
13
- content,
14
- contentType = "application/octet-stream",
15
- lineBreakNormalization = false,
16
- }) => {
17
- hash.update(
18
- lineBreakNormalization && CONTENT_TYPE.isTextual(contentType)
19
- ? ensureUnixLineBreaks(content)
20
- : content,
21
- )
9
+ augmentWithContent: (content) => {
10
+ hash.update(content)
22
11
  },
23
12
  augment: (value) => {
24
13
  hash.update(value)