@dxos/esbuild-plugins 0.6.13 → 0.6.14-main.2b6a0f3

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.
@@ -1,5 +1,5 @@
1
1
  export * from './fix-graceful-fs-plugin';
2
- export * from './fix-memdown-plugin';
2
+ export * from './node-external-plugin';
3
3
  export * from './node-globals-polyfill-plugin';
4
4
  export * from './node-modules-plugin';
5
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,uBAAuB,CAAC"}
package/dist/src/index.js CHANGED
@@ -18,7 +18,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
20
  __exportStar(require("./fix-graceful-fs-plugin"), exports);
21
- __exportStar(require("./fix-memdown-plugin"), exports);
21
+ __exportStar(require("./node-external-plugin"), exports);
22
22
  __exportStar(require("./node-globals-polyfill-plugin"), exports);
23
23
  __exportStar(require("./node-modules-plugin"), exports);
24
24
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;;;;;;;;;;;;;;AAEF,2DAAyC;AACzC,uDAAqC;AACrC,iEAA+C;AAC/C,wDAAsC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;;;;;;;;;;;;;;AAEF,2DAAyC;AACzC,yDAAuC;AACvC,iEAA+C;AAC/C,wDAAsC"}
@@ -0,0 +1,9 @@
1
+ import type { Plugin } from 'esbuild';
2
+ /**
3
+ * Rewrite `node:` imports to `@dxos/node-std` package and mark them as external.
4
+ */
5
+ export declare const NodeExternalPlugin: ({ injectGlobals, nodeStd }?: {
6
+ injectGlobals?: boolean | undefined;
7
+ nodeStd?: boolean | undefined;
8
+ }) => Plugin;
9
+ //# sourceMappingURL=node-external-plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-external-plugin.d.ts","sourceRoot":"","sources":["../../src/node-external-plugin.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAKtC;;GAEG;AACH,eAAO,MAAM,kBAAkB;;;MAAsD,MA8CnF,CAAC"}
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ //
3
+ // Copyright 2024 DXOS.org
4
+ //
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.NodeExternalPlugin = void 0;
7
+ // Keep in sync with packages/common/node-std/src/inject-globals.js
8
+ const GLOBALS = ['global', 'Buffer', 'process'];
9
+ /**
10
+ * Rewrite `node:` imports to `@dxos/node-std` package and mark them as external.
11
+ */
12
+ const NodeExternalPlugin = ({ injectGlobals = false, nodeStd = false } = {}) => ({
13
+ name: 'node-external',
14
+ setup: ({ initialOptions, onResolve, onLoad }) => {
15
+ if (initialOptions.platform === 'node') {
16
+ return;
17
+ }
18
+ if (injectGlobals) {
19
+ if (!nodeStd) {
20
+ throw new Error('Missing @dxos/node-std dependency.');
21
+ }
22
+ initialOptions.inject = ['@inject-globals'];
23
+ initialOptions.banner || (initialOptions.banner = {});
24
+ initialOptions.banner.js = 'import "@dxos/node-std/globals";';
25
+ }
26
+ onResolve({ filter: /^@inject-globals*/ }, (args) => {
27
+ return { path: '@inject-globals', namespace: 'inject-globals' };
28
+ });
29
+ onLoad({ filter: /^@inject-globals/, namespace: 'inject-globals' }, async (args) => {
30
+ return {
31
+ contents: `
32
+ export {
33
+ ${GLOBALS.join(',\n')}
34
+ } from '@dxos/node-std/inject-globals';
35
+ // Empty source map so that esbuild does not inject virtual source file names.
36
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIiJdLCJtYXBwaW5ncyI6IkEifQ==
37
+ `,
38
+ };
39
+ });
40
+ onResolve({ filter: /^@dxos\/node-std\/inject-globals$/ }, (args) => {
41
+ return { external: true, path: '@dxos/node-std/inject-globals' };
42
+ });
43
+ onResolve({ filter: /^node:.*/ }, (args) => {
44
+ if (!nodeStd) {
45
+ return { errors: [{ text: 'Missing @dxos/node-std dependency.' }] };
46
+ }
47
+ const module = args.path.replace(/^node:/, '');
48
+ return { external: true, path: `@dxos/node-std/${module}` };
49
+ });
50
+ },
51
+ });
52
+ exports.NodeExternalPlugin = NodeExternalPlugin;
53
+ //# sourceMappingURL=node-external-plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-external-plugin.js","sourceRoot":"","sources":["../../src/node-external-plugin.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;AAIF,mEAAmE;AACnE,MAAM,OAAO,GAAG,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;AAEhD;;GAEG;AACI,MAAM,kBAAkB,GAAG,CAAC,EAAE,aAAa,GAAG,KAAK,EAAE,OAAO,GAAG,KAAK,EAAE,GAAG,EAAE,EAAU,EAAE,CAAC,CAAC;IAC9F,IAAI,EAAE,eAAe;IACrB,KAAK,EAAE,CAAC,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE;QAC/C,IAAI,cAAc,CAAC,QAAQ,KAAK,MAAM,EAAE,CAAC;YACvC,OAAO;QACT,CAAC;QAED,IAAI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Q,EAAE,IAAI,EAAE,IAAI,EAAE,kBAAkB,MAAM,EAAE,EAAE,CAAC;QAC9D,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAC,CAAC;AA9CU,QAAA,kBAAkB,sBA8C5B"}
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@dxos/esbuild-plugins",
3
- "version": "0.6.13",
3
+ "version": "0.6.14-main.2b6a0f3",
4
4
  "homepage": "https://dxos.org",
5
5
  "bugs": "https://github.com/dxos/dxos/issues",
6
6
  "license": "MIT",
7
7
  "author": "DXOS.org",
8
+ "sideEffects": false,
8
9
  "main": "./dist/src/index.js",
9
10
  "types": "./dist/src/index.d.ts",
10
11
  "dependencies": {
package/project.json CHANGED
@@ -11,11 +11,11 @@
11
11
  "executor": "@nx/js:tsc",
12
12
  "options": {
13
13
  "main": "{projectRoot}/src/index.ts",
14
- "outputPath": "packages/common/esbuild-plugins/dist",
14
+ "outputPath": "{projectRoot}/dist",
15
15
  "transformers": [
16
16
  "@dxos/log-hook/transformer"
17
17
  ],
18
- "tsConfig": "packages/common/esbuild-plugins/tsconfig.json"
18
+ "tsConfig": "{projectRoot}/tsconfig.json"
19
19
  }
20
20
  },
21
21
  "lint": {}
package/src/index.ts CHANGED
@@ -3,6 +3,6 @@
3
3
  //
4
4
 
5
5
  export * from './fix-graceful-fs-plugin';
6
- export * from './fix-memdown-plugin';
6
+ export * from './node-external-plugin';
7
7
  export * from './node-globals-polyfill-plugin';
8
8
  export * from './node-modules-plugin';
@@ -0,0 +1,59 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import type { Plugin } from 'esbuild';
6
+
7
+ // Keep in sync with packages/common/node-std/src/inject-globals.js
8
+ const GLOBALS = ['global', 'Buffer', 'process'];
9
+
10
+ /**
11
+ * Rewrite `node:` imports to `@dxos/node-std` package and mark them as external.
12
+ */
13
+ export const NodeExternalPlugin = ({ injectGlobals = false, nodeStd = false } = {}): Plugin => ({
14
+ name: 'node-external',
15
+ setup: ({ initialOptions, onResolve, onLoad }) => {
16
+ if (initialOptions.platform === 'node') {
17
+ return;
18
+ }
19
+
20
+ if (injectGlobals) {
21
+ if (!nodeStd) {
22
+ throw new Error('Missing @dxos/node-std dependency.');
23
+ }
24
+
25
+ initialOptions.inject = ['@inject-globals'];
26
+ initialOptions.banner ||= {};
27
+ initialOptions.banner.js = 'import "@dxos/node-std/globals";';
28
+ }
29
+
30
+ onResolve({ filter: /^@inject-globals*/ }, (args) => {
31
+ return { path: '@inject-globals', namespace: 'inject-globals' };
32
+ });
33
+
34
+ onLoad({ filter: /^@inject-globals/, namespace: 'inject-globals' }, async (args) => {
35
+ return {
36
+ contents: `
37
+ export {
38
+ ${GLOBALS.join(',\n')}
39
+ } from '@dxos/node-std/inject-globals';
40
+ // Empty source map so that esbuild does not inject virtual source file names.
41
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIiJdLCJtYXBwaW5ncyI6IkEifQ==
42
+ `,
43
+ };
44
+ });
45
+
46
+ onResolve({ filter: /^@dxos\/node-std\/inject-globals$/ }, (args) => {
47
+ return { external: true, path: '@dxos/node-std/inject-globals' };
48
+ });
49
+
50
+ onResolve({ filter: /^node:.*/ }, (args) => {
51
+ if (!nodeStd) {
52
+ return { errors: [{ text: 'Missing @dxos/node-std dependency.' }] };
53
+ }
54
+
55
+ const module = args.path.replace(/^node:/, '');
56
+ return { external: true, path: `@dxos/node-std/${module}` };
57
+ });
58
+ },
59
+ });
@@ -1,6 +0,0 @@
1
- import type { Plugin } from 'esbuild';
2
- /**
3
- * Some odd path resolution in memdown package.
4
- */
5
- export declare const FixMemdownPlugin: () => Plugin;
6
- //# sourceMappingURL=fix-memdown-plugin.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fix-memdown-plugin.d.ts","sourceRoot":"","sources":["../../src/fix-memdown-plugin.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEtC;;GAEG;AACH,eAAO,MAAM,gBAAgB,QAAO,MASlC,CAAC"}
@@ -1,21 +0,0 @@
1
- "use strict";
2
- //
3
- // Copyright 2021 DXOS.org
4
- //
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.FixMemdownPlugin = void 0;
7
- /**
8
- * Some odd path resolution in memdown package.
9
- */
10
- const FixMemdownPlugin = () => ({
11
- name: 'fix-memdown-plugin',
12
- setup: ({ onResolve }) => {
13
- onResolve({ filter: /^immediate$/ }, (arg) => {
14
- return {
15
- path: require.resolve(arg.path, { paths: [arg.resolveDir] }),
16
- };
17
- });
18
- },
19
- });
20
- exports.FixMemdownPlugin = FixMemdownPlugin;
21
- //# sourceMappingURL=fix-memdown-plugin.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fix-memdown-plugin.js","sourceRoot":"","sources":["../../src/fix-memdown-plugin.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;AAIF;;GAEG;AACI,MAAM,gBAAgB,GAAG,GAAW,EAAE,CAAC,CAAC;IAC7C,IAAI,EAAE,oBAAoB;IAC1B,KAAK,EAAE,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE;QACvB,SAAS,CAAC,EAAE,MAAM,EAAE,aAAa,EAAE,EAAE,CAAC,GAAG,EAAE,EAAE;YAC3C,OAAO;gBACL,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC;aAC7D,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAC,CAAC;AATU,QAAA,gBAAgB,oBAS1B"}
@@ -1,19 +0,0 @@
1
- //
2
- // Copyright 2021 DXOS.org
3
- //
4
-
5
- import type { Plugin } from 'esbuild';
6
-
7
- /**
8
- * Some odd path resolution in memdown package.
9
- */
10
- export const FixMemdownPlugin = (): Plugin => ({
11
- name: 'fix-memdown-plugin',
12
- setup: ({ onResolve }) => {
13
- onResolve({ filter: /^immediate$/ }, (arg) => {
14
- return {
15
- path: require.resolve(arg.path, { paths: [arg.resolveDir] }),
16
- };
17
- });
18
- },
19
- });