@jsenv/core 34.0.0 → 34.0.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/dist/js/ws.js CHANGED
@@ -9,6 +9,9 @@ import require$$0$1 from "zlib";
9
9
  import require$$0$2 from "buffer";
10
10
  import require$$7 from "url";
11
11
 
12
+ function getDefaultExportFromCjs(x) {
13
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
14
+ }
12
15
  const {
13
16
  Duplex
14
17
  } = require$$0;
@@ -149,14 +152,9 @@ function createWebSocketStream(ws, options) {
149
152
  return duplex;
150
153
  }
151
154
  var stream = createWebSocketStream;
152
- var bufferUtilExports = {};
155
+ var stream$1 = /*@__PURE__*/getDefaultExportFromCjs(stream);
153
156
  var bufferUtil$1 = {
154
- get exports() {
155
- return bufferUtilExports;
156
- },
157
- set exports(v) {
158
- bufferUtilExports = v;
159
- }
157
+ exports: {}
160
158
  };
161
159
  var constants = {
162
160
  BINARY_TYPES: ['nodebuffer', 'arraybuffer', 'fragments'],
@@ -276,16 +274,17 @@ bufferUtil$1.exports = {
276
274
  if (!process.env.WS_NO_BUFFER_UTIL) {
277
275
  try {
278
276
  const bufferUtil = require('bufferutil');
279
- mask = bufferUtilExports.mask = function (source, mask, output, offset, length) {
277
+ mask = bufferUtil$1.exports.mask = function (source, mask, output, offset, length) {
280
278
  if (length < 48) _mask(source, mask, output, offset, length);else bufferUtil.mask(source, mask, output, offset, length);
281
279
  };
282
- unmask$1 = bufferUtilExports.unmask = function (buffer, mask) {
280
+ unmask$1 = bufferUtil$1.exports.unmask = function (buffer, mask) {
283
281
  if (buffer.length < 32) _unmask(buffer, mask);else bufferUtil.unmask(buffer, mask);
284
282
  };
285
283
  } catch (e) {
286
284
  // Continue regardless of the error.
287
285
  }
288
286
  }
287
+ var bufferUtilExports = bufferUtil$1.exports;
289
288
  const kDone = Symbol('kDone');
290
289
  const kRun = Symbol('kRun');
291
290
 
@@ -746,14 +745,8 @@ function inflateOnError(err) {
746
745
  err[kStatusCode$2] = 1007;
747
746
  this[kCallback](err);
748
747
  }
749
- var validationExports = {};
750
748
  var validation = {
751
- get exports() {
752
- return validationExports;
753
- },
754
- set exports(v) {
755
- validationExports = v;
756
- }
749
+ exports: {}
757
750
  };
758
751
  var isValidUTF8_1;
759
752
  const {
@@ -853,19 +846,20 @@ validation.exports = {
853
846
  tokenChars: tokenChars$2
854
847
  };
855
848
  if (isUtf8) {
856
- isValidUTF8_1 = validationExports.isValidUTF8 = function (buf) {
849
+ isValidUTF8_1 = validation.exports.isValidUTF8 = function (buf) {
857
850
  return buf.length < 24 ? _isValidUTF8(buf) : isUtf8(buf);
858
851
  };
859
852
  } /* istanbul ignore else */else if (!process.env.WS_NO_UTF_8_VALIDATE) {
860
853
  try {
861
854
  const isValidUTF8 = require('utf-8-validate');
862
- isValidUTF8_1 = validationExports.isValidUTF8 = function (buf) {
855
+ isValidUTF8_1 = validation.exports.isValidUTF8 = function (buf) {
863
856
  return buf.length < 32 ? _isValidUTF8(buf) : isValidUTF8(buf);
864
857
  };
865
858
  } catch (e) {
866
859
  // Continue regardless of the error.
867
860
  }
868
861
  }
862
+ var validationExports = validation.exports;
869
863
  const {
870
864
  Writable
871
865
  } = require$$0;
@@ -1309,6 +1303,7 @@ function error(ErrorCtor, message, prefix, statusCode, errorCode) {
1309
1303
  err[kStatusCode$1] = statusCode;
1310
1304
  return err;
1311
1305
  }
1306
+ var receiver$1 = /*@__PURE__*/getDefaultExportFromCjs(receiver);
1312
1307
 
1313
1308
  /* eslint no-unused-vars: ["error", { "varsIgnorePattern": "^net|tls$" }] */
1314
1309
  const {
@@ -1725,6 +1720,7 @@ let Sender$1 = class Sender {
1725
1720
  }
1726
1721
  };
1727
1722
  var sender = Sender$1;
1723
+ var sender$1 = /*@__PURE__*/getDefaultExportFromCjs(sender);
1728
1724
  const {
1729
1725
  kForOnEventAttribute: kForOnEventAttribute$1,
1730
1726
  kListener: kListener$1
@@ -3316,6 +3312,7 @@ function socketOnError$1() {
3316
3312
  this.destroy();
3317
3313
  }
3318
3314
  }
3315
+ var WebSocket$2 = /*@__PURE__*/getDefaultExportFromCjs(websocket);
3319
3316
  const {
3320
3317
  tokenChars
3321
3318
  } = validationExports;
@@ -3801,5 +3798,6 @@ function abortHandshakeOrEmitwsClientError(server, req, socket, code, message) {
3801
3798
  abortHandshake(socket, code, message);
3802
3799
  }
3803
3800
  }
3801
+ var websocketServer$1 = /*@__PURE__*/getDefaultExportFromCjs(websocketServer);
3804
3802
 
3805
- export { receiver as Receiver, sender as Sender, websocket as WebSocket, websocketServer as WebSocketServer, stream as createWebSocketStream, websocket as default };
3803
+ export { receiver$1 as Receiver, sender$1 as Sender, WebSocket$2 as WebSocket, websocketServer$1 as WebSocketServer, stream$1 as createWebSocketStream, WebSocket$2 as default };
package/dist/jsenv.js CHANGED
@@ -14753,21 +14753,7 @@ function default_1({
14753
14753
  };
14754
14754
  }
14755
14755
 
14756
- /*
14757
- * When systemjs format is used by babel, it will generated UID based on
14758
- * the import specifier:
14759
- * https://github.com/babel/babel/blob/97d1967826077f15e766778c0d64711399e9a72a/packages/babel-plugin-transform-modules-systemjs/src/index.ts#L498
14760
- * But at this stage import specifier are absolute file urls
14761
- * So without minification these specifier are long and dependent
14762
- * on where the files are on the filesystem.
14763
- * This can be mitigated by minification that will rename them.
14764
- * But to fix this issue once and for all I have copy-pasted
14765
- * "@babel/plugin-transform-modules-systemjs" to introduce
14766
- * "generateIdentifierHint" options and prevent that from hapenning
14767
- */
14768
- const TRANSFORM_MODULES_SYSTEMJS_PATH = fileURLToPath(new URL("./js/babel_plugin_transform_modules_systemjs.cjs", import.meta.url));
14769
14756
  const convertJsModuleToJsClassic = async ({
14770
- rootDirectoryUrl,
14771
14757
  systemJsInjection,
14772
14758
  systemJsClientFileUrl,
14773
14759
  urlInfo,
@@ -14792,15 +14778,8 @@ const convertJsModuleToJsClassic = async ({
14792
14778
  babelPlugins: [...(jsClassicFormat === "system" ? [
14793
14779
  // proposal-dynamic-import required with systemjs for babel8:
14794
14780
  // https://github.com/babel/babel/issues/10746
14795
- requireFromJsenv("@babel/plugin-proposal-dynamic-import"), [
14796
- // eslint-disable-next-line import/no-dynamic-require
14797
- requireFromJsenv(TRANSFORM_MODULES_SYSTEMJS_PATH), {
14798
- generateIdentifierHint: key => {
14799
- if (key.startsWith("file://")) {
14800
- return urlToRelativeUrl(key, rootDirectoryUrl);
14801
- }
14802
- return key;
14803
- }
14781
+ requireFromJsenv("@babel/plugin-proposal-dynamic-import"), requireFromJsenv("@babel/plugin-transform-modules-systemjs"), [babelPluginRelativeImports, {
14782
+ rootUrl: jsModuleUrlInfo.url
14804
14783
  }], [default_1, {
14805
14784
  asyncAwait: false,
14806
14785
  // already handled + we might not needs it at all
@@ -14809,7 +14788,9 @@ const convertJsModuleToJsClassic = async ({
14809
14788
  asyncAwait: false,
14810
14789
  // already handled + we might not needs it at all
14811
14790
  topLevelAwait: "simple"
14812
- }], babelPluginTransformImportMetaUrl, babelPluginTransformImportMetaResolve, requireFromJsenv("@babel/plugin-transform-modules-umd")])],
14791
+ }], babelPluginTransformImportMetaUrl, babelPluginTransformImportMetaResolve, requireFromJsenv("@babel/plugin-transform-modules-umd"), [babelPluginRelativeImports, {
14792
+ rootUrl: jsModuleUrlInfo.url
14793
+ }]])],
14813
14794
  urlInfo: jsModuleUrlInfo
14814
14795
  });
14815
14796
  let sourcemap = jsModuleUrlInfo.sourcemap;
@@ -14846,6 +14827,68 @@ const convertJsModuleToJsClassic = async ({
14846
14827
  };
14847
14828
  };
14848
14829
 
14830
+ /*
14831
+ * When systemjs or umd format is used by babel, it will generated UID based on
14832
+ * the import specifier:
14833
+ * https://github.com/babel/babel/blob/97d1967826077f15e766778c0d64711399e9a72a/packages/babel-plugin-transform-modules-systemjs/src/index.ts#L498
14834
+ * But at this stage import specifier are absolute file urls
14835
+ * This can be mitigated by minification that will rename them.
14836
+ * But to fix this issue once and for all there is babelPluginRelativeImports below
14837
+ */
14838
+ const babelPluginRelativeImports = babel => {
14839
+ const t = babel.types;
14840
+ const replaceSpecifierAtPath = (path, state) => {
14841
+ const specifier = path.node.value;
14842
+ if (specifier.startsWith("file://")) {
14843
+ const specifierRelative = urlToRelativeUrl(specifier, state.opts.rootUrl);
14844
+ path.replaceWith(t.stringLiteral(specifierRelative));
14845
+ }
14846
+ };
14847
+ return {
14848
+ name: "relative-imports",
14849
+ visitor: {
14850
+ CallExpression: (path, state) => {
14851
+ if (path.node.callee.type !== "Import") {
14852
+ // Some other function call, not import();
14853
+ return;
14854
+ }
14855
+ if (path.node.arguments[0].type !== "StringLiteral") {
14856
+ // Non-string argument, probably a variable or expression, e.g.
14857
+ // import(moduleId)
14858
+ // import('./' + moduleName)
14859
+ return;
14860
+ }
14861
+ const sourcePath = path.get("arguments")[0];
14862
+ if (sourcePath.node.type === "StringLiteral") {
14863
+ replaceSpecifierAtPath(sourcePath, state);
14864
+ }
14865
+ },
14866
+ ImportDeclaration: (path, state) => {
14867
+ const sourcePath = path.get("source");
14868
+ replaceSpecifierAtPath(sourcePath, state);
14869
+ },
14870
+ ExportAllDeclaration: (path, state) => {
14871
+ const sourcePath = path.get("source");
14872
+ replaceSpecifierAtPath(sourcePath, state);
14873
+ },
14874
+ ExportNamedDeclaration: (path, state) => {
14875
+ if (!path.node.source) {
14876
+ // This export has no "source", so it's probably
14877
+ // a local variable or function, e.g.
14878
+ // export { varName }
14879
+ // export const constName = ...
14880
+ // export function funcName() {}
14881
+ return;
14882
+ }
14883
+ const sourcePath = path.get("source");
14884
+ if (sourcePath.node.type === "StringLiteral") {
14885
+ replaceSpecifierAtPath(sourcePath, state);
14886
+ }
14887
+ }
14888
+ }
14889
+ };
14890
+ };
14891
+
14849
14892
  /*
14850
14893
  * - propagate ?as_js_classic to urls
14851
14894
  * - perform conversion from js module to js classic when url uses ?as_js_classic
@@ -17539,6 +17582,7 @@ const jsenvPluginHttpUrls = () => {
17539
17582
  * and create a variable named "undefined"
17540
17583
  */
17541
17584
  const injectSupervisorIntoJs = async ({
17585
+ webServer,
17542
17586
  content,
17543
17587
  url,
17544
17588
  type,
@@ -17564,7 +17608,7 @@ const injectSupervisorIntoJs = async ({
17564
17608
  specifier: sourcemapDataUrl
17565
17609
  });
17566
17610
  code = `${code}
17567
- //# sourceURL=${url}`;
17611
+ //# sourceURL=${urlToRelativeUrl(url, webServer.rootDirectoryUrl)}`;
17568
17612
  return code;
17569
17613
  };
17570
17614
  const babelPluginJsModuleSupervisor = babel => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/core",
3
- "version": "34.0.0",
3
+ "version": "34.0.2",
4
4
  "description": "Tool to develop, test and build js projects",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -66,14 +66,14 @@
66
66
  "@c88/v8-coverage": "0.1.1",
67
67
  "@financial-times/polyfill-useragent-normaliser": "1.10.2",
68
68
  "@jsenv/abort": "4.2.4",
69
- "@jsenv/ast": "3.0.4",
69
+ "@jsenv/ast": "3.0.5",
70
70
  "@jsenv/babel-plugins": "1.1.5",
71
71
  "@jsenv/filesystem": "4.2.3",
72
72
  "@jsenv/importmap": "1.2.1",
73
73
  "@jsenv/integrity": "0.0.1",
74
74
  "@jsenv/log": "3.3.4",
75
75
  "@jsenv/node-esm-resolution": "1.0.1",
76
- "@jsenv/plugin-bundling": "2.1.3",
76
+ "@jsenv/plugin-bundling": "2.1.4",
77
77
  "@jsenv/server": "15.0.2",
78
78
  "@jsenv/sourcemap": "1.0.10",
79
79
  "@jsenv/uneval": "1.6.0",
@@ -100,18 +100,18 @@
100
100
  "@babel/plugin-syntax-import-assertions": "7.20.0",
101
101
  "@jsenv/assert": "./packages/assert/",
102
102
  "@jsenv/eslint-config": "./packages/eslint-config/",
103
- "@jsenv/file-size-impact": "14.0.0",
103
+ "@jsenv/file-size-impact": "14.1.0",
104
104
  "@jsenv/https-local": "3.0.6",
105
105
  "@jsenv/package-workspace": "0.5.1",
106
106
  "@jsenv/performance-impact": "4.1.0",
107
107
  "@jsenv/plugin-globals": "./packages/jsenv-plugin-globals/",
108
108
  "@jsenv/plugin-minification": "./packages/jsenv-plugin-minification/",
109
109
  "@jsenv/plugin-placeholders": "./packages/jsenv-plugin-placeholders/",
110
- "eslint": "8.36.0",
110
+ "eslint": "8.38.0",
111
111
  "eslint-plugin-html": "7.1.0",
112
112
  "eslint-plugin-import": "2.27.5",
113
113
  "eslint-plugin-react": "7.32.2",
114
- "playwright": "1.32.1",
114
+ "playwright": "1.32.3",
115
115
  "prettier": "2.8.7"
116
116
  }
117
117
  }
@@ -36,10 +36,12 @@
36
36
  * and create a variable named "undefined"
37
37
  */
38
38
 
39
+ import { urlToRelativeUrl } from "@jsenv/urls"
39
40
  import { applyBabelPlugins } from "@jsenv/ast"
40
41
  import { SOURCEMAP, generateSourcemapDataUrl } from "@jsenv/sourcemap"
41
42
 
42
43
  export const injectSupervisorIntoJs = async ({
44
+ webServer,
43
45
  content,
44
46
  url,
45
47
  type,
@@ -66,7 +68,7 @@ export const injectSupervisorIntoJs = async ({
66
68
  specifier: sourcemapDataUrl,
67
69
  })
68
70
  code = `${code}
69
- //# sourceURL=${url}`
71
+ //# sourceURL=${urlToRelativeUrl(url, webServer.rootDirectoryUrl)}`
70
72
  return code
71
73
  }
72
74
 
@@ -1,4 +1,3 @@
1
- import { fileURLToPath } from "node:url"
2
1
  import { urlToRelativeUrl } from "@jsenv/urls"
3
2
  import { readFileSync } from "@jsenv/filesystem"
4
3
  import {
@@ -17,24 +16,7 @@ import { babelPluginTransformImportMetaResolve } from "./helpers/babel_plugin_tr
17
16
  // because of https://github.com/rpetrich/babel-plugin-transform-async-to-promises/issues/84
18
17
  import customAsyncToPromises from "./async-to-promises.js"
19
18
 
20
- /*
21
- * When systemjs format is used by babel, it will generated UID based on
22
- * the import specifier:
23
- * https://github.com/babel/babel/blob/97d1967826077f15e766778c0d64711399e9a72a/packages/babel-plugin-transform-modules-systemjs/src/index.ts#L498
24
- * But at this stage import specifier are absolute file urls
25
- * So without minification these specifier are long and dependent
26
- * on where the files are on the filesystem.
27
- * This can be mitigated by minification that will rename them.
28
- * But to fix this issue once and for all I have copy-pasted
29
- * "@babel/plugin-transform-modules-systemjs" to introduce
30
- * "generateIdentifierHint" options and prevent that from hapenning
31
- */
32
- const TRANSFORM_MODULES_SYSTEMJS_PATH = fileURLToPath(
33
- new URL("./babel_plugin_transform_modules_systemjs.cjs", import.meta.url),
34
- )
35
-
36
19
  export const convertJsModuleToJsClassic = async ({
37
- rootDirectoryUrl,
38
20
  systemJsInjection,
39
21
  systemJsClientFileUrl,
40
22
  urlInfo,
@@ -60,18 +42,8 @@ export const convertJsModuleToJsClassic = async ({
60
42
  // proposal-dynamic-import required with systemjs for babel8:
61
43
  // https://github.com/babel/babel/issues/10746
62
44
  requireFromJsenv("@babel/plugin-proposal-dynamic-import"),
63
- [
64
- // eslint-disable-next-line import/no-dynamic-require
65
- requireFromJsenv(TRANSFORM_MODULES_SYSTEMJS_PATH),
66
- {
67
- generateIdentifierHint: (key) => {
68
- if (key.startsWith("file://")) {
69
- return urlToRelativeUrl(key, rootDirectoryUrl)
70
- }
71
- return key
72
- },
73
- },
74
- ],
45
+ requireFromJsenv("@babel/plugin-transform-modules-systemjs"),
46
+ [babelPluginRelativeImports, { rootUrl: jsModuleUrlInfo.url }],
75
47
  [
76
48
  customAsyncToPromises,
77
49
  {
@@ -91,6 +63,7 @@ export const convertJsModuleToJsClassic = async ({
91
63
  babelPluginTransformImportMetaUrl,
92
64
  babelPluginTransformImportMetaResolve,
93
65
  requireFromJsenv("@babel/plugin-transform-modules-umd"),
66
+ [babelPluginRelativeImports, { rootUrl: jsModuleUrlInfo.url }],
94
67
  ]),
95
68
  ],
96
69
  urlInfo: jsModuleUrlInfo,
@@ -132,3 +105,67 @@ export const convertJsModuleToJsClassic = async ({
132
105
  sourcemap,
133
106
  }
134
107
  }
108
+
109
+ /*
110
+ * When systemjs or umd format is used by babel, it will generated UID based on
111
+ * the import specifier:
112
+ * https://github.com/babel/babel/blob/97d1967826077f15e766778c0d64711399e9a72a/packages/babel-plugin-transform-modules-systemjs/src/index.ts#L498
113
+ * But at this stage import specifier are absolute file urls
114
+ * This can be mitigated by minification that will rename them.
115
+ * But to fix this issue once and for all there is babelPluginRelativeImports below
116
+ */
117
+ const babelPluginRelativeImports = (babel) => {
118
+ const t = babel.types
119
+
120
+ const replaceSpecifierAtPath = (path, state) => {
121
+ const specifier = path.node.value
122
+ if (specifier.startsWith("file://")) {
123
+ const specifierRelative = urlToRelativeUrl(specifier, state.opts.rootUrl)
124
+ path.replaceWith(t.stringLiteral(specifierRelative))
125
+ }
126
+ }
127
+
128
+ return {
129
+ name: "relative-imports",
130
+ visitor: {
131
+ CallExpression: (path, state) => {
132
+ if (path.node.callee.type !== "Import") {
133
+ // Some other function call, not import();
134
+ return
135
+ }
136
+ if (path.node.arguments[0].type !== "StringLiteral") {
137
+ // Non-string argument, probably a variable or expression, e.g.
138
+ // import(moduleId)
139
+ // import('./' + moduleName)
140
+ return
141
+ }
142
+ const sourcePath = path.get("arguments")[0]
143
+ if (sourcePath.node.type === "StringLiteral") {
144
+ replaceSpecifierAtPath(sourcePath, state)
145
+ }
146
+ },
147
+ ImportDeclaration: (path, state) => {
148
+ const sourcePath = path.get("source")
149
+ replaceSpecifierAtPath(sourcePath, state)
150
+ },
151
+ ExportAllDeclaration: (path, state) => {
152
+ const sourcePath = path.get("source")
153
+ replaceSpecifierAtPath(sourcePath, state)
154
+ },
155
+ ExportNamedDeclaration: (path, state) => {
156
+ if (!path.node.source) {
157
+ // This export has no "source", so it's probably
158
+ // a local variable or function, e.g.
159
+ // export { varName }
160
+ // export const constName = ...
161
+ // export function funcName() {}
162
+ return
163
+ }
164
+ const sourcePath = path.get("source")
165
+ if (sourcePath.node.type === "StringLiteral") {
166
+ replaceSpecifierAtPath(sourcePath, state)
167
+ }
168
+ },
169
+ },
170
+ }
171
+ }