@knighted/module 1.5.1 → 1.6.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/README.md +4 -1
- package/dist/ast.d.ts +2 -2
- package/dist/async.d.ts +1 -1
- package/dist/cjs/ast.d.cts +2 -2
- package/dist/cjs/async.d.cts +1 -1
- package/dist/cjs/cli.cjs +12 -13
- package/dist/cjs/exports.d.cts +1 -2
- package/dist/cjs/format.cjs +12 -12
- package/dist/cjs/format.d.cts +2 -2
- package/dist/cjs/formatVisitor.d.cts +1 -1
- package/dist/cjs/formatters/identifier.cjs +1 -1
- package/dist/cjs/identifiers.d.cts +2 -3
- package/dist/cjs/idiomaticPlan.d.cts +0 -1
- package/dist/cjs/lowerEsmToCjs.d.cts +1 -2
- package/dist/cjs/module.cjs +7 -6
- package/dist/cjs/module.d.cts +1 -1
- package/dist/cjs/pipeline/buildEsmPrelude.cjs +1 -1
- package/dist/cjs/pipeline/lowerCjsRequireToImports.cjs +1 -1
- package/dist/cjs/pipeline/lowerEsmToCjs.cjs +2 -3
- package/dist/cjs/specifier.cjs +1 -1
- package/dist/cjs/specifier.d.cts +1 -1
- package/dist/cjs/utils/exports.cjs +1 -2
- package/dist/cjs/utils/identifiers.cjs +3 -4
- package/dist/cjs/walk.d.cts +1 -1
- package/dist/cli.js +12 -13
- package/dist/exports.d.ts +1 -2
- package/dist/format.d.ts +2 -2
- package/dist/format.js +9 -9
- package/dist/formatVisitor.d.ts +1 -1
- package/dist/formatters/identifier.js +1 -1
- package/dist/helpers/ast.d.ts +2 -2
- package/dist/helpers/async.d.ts +1 -1
- package/dist/helpers/identifier.js +1 -0
- package/dist/identifiers.d.ts +2 -3
- package/dist/idiomaticPlan.d.ts +0 -1
- package/dist/lowerEsmToCjs.d.ts +1 -2
- package/dist/module.d.ts +1 -1
- package/dist/module.js +13 -15
- package/dist/pipeline/buildEsmPrelude.js +1 -1
- package/dist/pipeline/formatVisitor.d.ts +1 -1
- package/dist/pipeline/idiomaticPlan.d.ts +0 -1
- package/dist/pipeline/lowerCjsRequireToImports.js +1 -1
- package/dist/pipeline/lowerEsmToCjs.d.ts +1 -2
- package/dist/pipeline/lowerEsmToCjs.js +2 -2
- package/dist/specifier.d.ts +1 -1
- package/dist/specifier.js +1 -1
- package/dist/utils/exports.d.ts +1 -2
- package/dist/utils/exports.js +1 -2
- package/dist/utils/identifiers.d.ts +2 -3
- package/dist/utils/identifiers.js +3 -3
- package/dist/walk.d.ts +1 -1
- package/package.json +24 -12
- package/dist/cjs/expressionStatement.d.cts +0 -4
- package/dist/cjs/formatters/expressionStatement.cjs +0 -49
- package/dist/expressionStatement.d.ts +0 -4
- package/dist/formatters/expressionStatement.d.ts +0 -4
- package/dist/formatters/expressionStatement.js +0 -42
package/README.md
CHANGED
|
@@ -25,7 +25,7 @@ By default `@knighted/module` transforms the one-to-one [differences between ES
|
|
|
25
25
|
|
|
26
26
|
## Requirements
|
|
27
27
|
|
|
28
|
-
- Node 22.21.1
|
|
28
|
+
- Node >= 22.21.1 (<23), >= 24 (<25), or >= 26 (<27)
|
|
29
29
|
|
|
30
30
|
## Install
|
|
31
31
|
|
|
@@ -222,4 +222,7 @@ dub -t commonjs "src/**/*.{ts,js,mts,cts}" --ignore node_modules/** --transform-
|
|
|
222
222
|
tsc
|
|
223
223
|
```
|
|
224
224
|
|
|
225
|
+
> [!NOTE]
|
|
226
|
+
> With TypeScript 6+, when a `tsconfig.json` is present, `rootDir` defaults to `.`. If your config uses `outDir` and includes sources under `src`, set `"rootDir": "./src"` explicitly to avoid TS5011.
|
|
227
|
+
|
|
225
228
|
This pre-`tsc` step rewrites globals-only (keeps import/export syntax) so the TypeScript checker sees already-rewritten sources; runtime semantics still match the target build.
|
package/dist/ast.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type { Node } from 'oxc-parser';
|
|
2
2
|
import type { CjsExport } from '../types.js';
|
|
3
3
|
export type { Node };
|
|
4
|
-
|
|
4
|
+
type IdentifierNode = Extract<Node, {
|
|
5
5
|
type: 'Identifier';
|
|
6
6
|
}>;
|
|
7
7
|
export type LiteralNode = Extract<Node, {
|
|
8
8
|
type: 'Literal';
|
|
9
9
|
value?: unknown;
|
|
10
10
|
}>;
|
|
11
|
-
|
|
11
|
+
type MemberExpressionNode = Extract<Node, {
|
|
12
12
|
type: 'MemberExpression';
|
|
13
13
|
}>;
|
|
14
14
|
export type CallExpressionNode = Extract<Node, {
|
package/dist/async.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Node, type ProgramNode } from './ast.js';
|
|
2
2
|
declare const hasTopLevelAwait: (program: ProgramNode) => boolean;
|
|
3
3
|
declare const isAsyncContext: (ancestors: Node[]) => boolean;
|
|
4
4
|
export { hasTopLevelAwait, isAsyncContext };
|
package/dist/cjs/ast.d.cts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type { Node } from 'oxc-parser';
|
|
2
2
|
import type { CjsExport } from '../types.cjs';
|
|
3
3
|
export type { Node };
|
|
4
|
-
|
|
4
|
+
type IdentifierNode = Extract<Node, {
|
|
5
5
|
type: 'Identifier';
|
|
6
6
|
}>;
|
|
7
7
|
export type LiteralNode = Extract<Node, {
|
|
8
8
|
type: 'Literal';
|
|
9
9
|
value?: unknown;
|
|
10
10
|
}>;
|
|
11
|
-
|
|
11
|
+
type MemberExpressionNode = Extract<Node, {
|
|
12
12
|
type: 'MemberExpression';
|
|
13
13
|
}>;
|
|
14
14
|
export type CallExpressionNode = Extract<Node, {
|
package/dist/cjs/async.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Node, type ProgramNode } from './ast.cjs';
|
|
2
2
|
declare const hasTopLevelAwait: (program: ProgramNode) => boolean;
|
|
3
3
|
declare const isAsyncContext: (ancestors: Node[]) => boolean;
|
|
4
4
|
export { hasTopLevelAwait, isAsyncContext };
|
package/dist/cjs/cli.cjs
CHANGED
|
@@ -5,17 +5,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.runCli = void 0;
|
|
8
|
-
var _nodeProcess = require("node:process");
|
|
9
|
-
var _nodeUtil = require("node:util");
|
|
10
8
|
var _promises = require("node:fs/promises");
|
|
11
9
|
var _nodePath = require("node:path");
|
|
12
|
-
var
|
|
10
|
+
var _nodeProcess = require("node:process");
|
|
11
|
+
var _nodeUtil = require("node:util");
|
|
12
|
+
var _format = require("./format.cjs");
|
|
13
13
|
var _module = require("./module.cjs");
|
|
14
14
|
var _parse = require("./parse.cjs");
|
|
15
|
-
var _format = require("./format.cjs");
|
|
16
15
|
var _specifier = require("./specifier.cjs");
|
|
17
|
-
var _lang = require("./utils/lang.cjs");
|
|
18
16
|
var _builtinSpecifiers = require("./utils/builtinSpecifiers.cjs");
|
|
17
|
+
var _lang = require("./utils/lang.cjs");
|
|
19
18
|
const defaultOptions = {
|
|
20
19
|
target: 'commonjs',
|
|
21
20
|
sourceType: 'auto',
|
|
@@ -387,14 +386,14 @@ const normalizeSourceMapArgv = argv => {
|
|
|
387
386
|
const expandFiles = async (patterns, cwd, ignore) => {
|
|
388
387
|
const files = new Set();
|
|
389
388
|
for (const pattern of patterns) {
|
|
390
|
-
const
|
|
389
|
+
for await (const match of (0, _promises.glob)(pattern, {
|
|
391
390
|
cwd,
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
391
|
+
exclude: ignore,
|
|
392
|
+
withFileTypes: true
|
|
393
|
+
})) {
|
|
394
|
+
if (match.isDirectory()) continue;
|
|
395
|
+
files.add((0, _nodePath.resolve)(match.parentPath, match.name));
|
|
396
|
+
}
|
|
398
397
|
}
|
|
399
398
|
return [...files];
|
|
400
399
|
};
|
|
@@ -685,7 +684,7 @@ if (import.meta.main) {
|
|
|
685
684
|
runCli().then(code => {
|
|
686
685
|
if (code !== 0) process.exit(code);
|
|
687
686
|
}, err => {
|
|
688
|
-
// eslint-disable-next-line no-console
|
|
687
|
+
// eslint-disable-next-line no-console
|
|
689
688
|
console.error(err);
|
|
690
689
|
process.exit(1);
|
|
691
690
|
});
|
package/dist/cjs/exports.d.cts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import type { Node } from 'oxc-parser';
|
|
2
2
|
import type { CjsExport } from '../types.cjs';
|
|
3
3
|
declare const exportsRename = "__exports";
|
|
4
|
-
declare const requireMainRgx: RegExp;
|
|
5
4
|
type ExportsMap = Map<string, CjsExport> & {
|
|
6
5
|
hasUnsupportedExportWrite?: boolean;
|
|
7
6
|
};
|
|
8
7
|
declare const collectCjsExports: (ast: Node) => Promise<ExportsMap>;
|
|
9
|
-
export { exportsRename,
|
|
8
|
+
export { exportsRename, collectCjsExports };
|
package/dist/cjs/format.cjs
CHANGED
|
@@ -5,26 +5,26 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.dualPackageHazardDiagnostics = exports.collectDualPackageUsage = void 0;
|
|
7
7
|
exports.format = format;
|
|
8
|
-
var _nodePath = require("node:path");
|
|
9
8
|
var _promises = require("node:fs/promises");
|
|
9
|
+
var _nodePath = require("node:path");
|
|
10
10
|
var _magicString = _interopRequireDefault(require("magic-string"));
|
|
11
|
-
var _async = require("./helpers/async.cjs");
|
|
12
|
-
var _identifier = require("./helpers/identifier.cjs");
|
|
13
11
|
var _assignmentExpression = require("./formatters/assignmentExpression.cjs");
|
|
14
|
-
var
|
|
12
|
+
var _identifier = require("./formatters/identifier.cjs");
|
|
15
13
|
var _memberExpression = require("./formatters/memberExpression.cjs");
|
|
16
14
|
var _metaProperty = require("./formatters/metaProperty.cjs");
|
|
17
|
-
var
|
|
15
|
+
var _async = require("./helpers/async.cjs");
|
|
16
|
+
var _identifier2 = require("./helpers/identifier.cjs");
|
|
18
17
|
var _buildEsmPrelude = require("./pipeline/buildEsmPrelude.cjs");
|
|
19
18
|
var _exportBagToEsm = require("./pipeline/exportBagToEsm.cjs");
|
|
20
|
-
var _lowerCjsRequireToImports = require("./pipeline/lowerCjsRequireToImports.cjs");
|
|
21
|
-
var _lowerEsmToCjs = require("./pipeline/lowerEsmToCjs.cjs");
|
|
22
19
|
var _formatVisitor = require("./pipeline/formatVisitor.cjs");
|
|
20
|
+
var _idiomaticPlan = require("./pipeline/idiomaticPlan.cjs");
|
|
23
21
|
var _interopHelpers = require("./pipeline/interopHelpers.cjs");
|
|
22
|
+
var _lowerCjsRequireToImports = require("./pipeline/lowerCjsRequireToImports.cjs");
|
|
23
|
+
var _lowerEsmToCjs = require("./pipeline/lowerEsmToCjs.cjs");
|
|
24
|
+
var _builtinSpecifiers = require("./utils/builtinSpecifiers.cjs");
|
|
24
25
|
var _exports = require("./utils/exports.cjs");
|
|
25
26
|
var _identifiers = require("./utils/identifiers.cjs");
|
|
26
27
|
var _url = require("./utils/url.cjs");
|
|
27
|
-
var _builtinSpecifiers = require("./utils/builtinSpecifiers.cjs");
|
|
28
28
|
var _walk = require("./walk.cjs");
|
|
29
29
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
30
30
|
const isRequireMainMember = (node, shadowed) => node.type === 'MemberExpression' && node.object.type === 'Identifier' && node.object.name === 'require' && !shadowed.has('require') && node.property.type === 'Identifier' && node.property.name === 'main';
|
|
@@ -313,12 +313,12 @@ async function format(src, ast, opts) {
|
|
|
313
313
|
return;
|
|
314
314
|
}
|
|
315
315
|
if (diag.level === 'warning') {
|
|
316
|
-
// eslint-disable-next-line no-console
|
|
316
|
+
// eslint-disable-next-line no-console
|
|
317
317
|
console.warn(diag.message);
|
|
318
318
|
return;
|
|
319
319
|
}
|
|
320
320
|
|
|
321
|
-
// eslint-disable-next-line no-console
|
|
321
|
+
// eslint-disable-next-line no-console
|
|
322
322
|
console.error(diag.message);
|
|
323
323
|
};
|
|
324
324
|
const diagOnce = (level, codeId, message, loc) => {
|
|
@@ -447,11 +447,11 @@ async function format(src, ast, opts) {
|
|
|
447
447
|
isStaticRequire: _lowerCjsRequireToImports.isStaticRequire,
|
|
448
448
|
isAsyncContext: _async.isAsyncContext,
|
|
449
449
|
isValidUrl: _url.isValidUrl,
|
|
450
|
-
isIdentifierName:
|
|
450
|
+
isIdentifierName: _identifier2.isIdentifierName,
|
|
451
451
|
assignmentExpression: _assignmentExpression.assignmentExpression,
|
|
452
452
|
metaProperty: _metaProperty.metaProperty,
|
|
453
453
|
memberExpression: _memberExpression.memberExpression,
|
|
454
|
-
identifier:
|
|
454
|
+
identifier: _identifier.identifier
|
|
455
455
|
}, walkState)
|
|
456
456
|
});
|
|
457
457
|
({
|
package/dist/cjs/format.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { Node, ParseResult } from 'oxc-parser';
|
|
2
1
|
import MagicString from 'magic-string';
|
|
2
|
+
import type { Node, ParseResult } from 'oxc-parser';
|
|
3
3
|
import type { Diagnostic, FormatterOptions } from './types.cjs';
|
|
4
4
|
type HazardLevel = 'warning' | 'error';
|
|
5
|
-
|
|
5
|
+
type PackageUse = {
|
|
6
6
|
spec: string;
|
|
7
7
|
subpath: string;
|
|
8
8
|
loc?: {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type MagicString from 'magic-string';
|
|
2
|
-
import type { Node, CallExpressionNode } from '../helpers/ast.cjs';
|
|
3
2
|
import type { IdentifierName } from 'oxc-parser';
|
|
4
3
|
import type { WarnOnce } from './exportBagToEsm.cjs';
|
|
4
|
+
import type { Node, CallExpressionNode } from '../helpers/ast.cjs';
|
|
5
5
|
import type { FormatterOptions, ExportsMeta } from '../types.cjs';
|
|
6
6
|
type AssignmentExpressionFn = (typeof import('../formatters/assignmentExpression.cjs'))['assignmentExpression'];
|
|
7
7
|
type IdentifierFn = (typeof import('../formatters/identifier.cjs'))['identifier'];
|
|
@@ -4,8 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.identifier = void 0;
|
|
7
|
-
var _exports = require("../utils/exports.cjs");
|
|
8
7
|
var _identifier = require("../helpers/identifier.cjs");
|
|
8
|
+
var _exports = require("../utils/exports.cjs");
|
|
9
9
|
const identifier = ({
|
|
10
10
|
node,
|
|
11
11
|
ancestors,
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { Node } from 'oxc-parser';
|
|
2
|
-
import type { IdentMeta
|
|
3
|
-
declare const collectScopeIdentifiers: (node: Node, scopes: Scope[]) => void;
|
|
2
|
+
import type { IdentMeta } from '../types.cjs';
|
|
4
3
|
/**
|
|
5
4
|
* Collects all module scope identifiers in the AST.
|
|
6
5
|
*
|
|
@@ -16,4 +15,4 @@ declare const collectScopeIdentifiers: (node: Node, scopes: Scope[]) => void;
|
|
|
16
15
|
* which are also valid module scope identifiers.
|
|
17
16
|
*/
|
|
18
17
|
declare const collectModuleIdentifiers: (ast: Node, hoisting?: boolean) => Promise<Map<string, IdentMeta>>;
|
|
19
|
-
export {
|
|
18
|
+
export { collectModuleIdentifiers };
|
|
@@ -25,4 +25,3 @@ type BuildIdiomaticPlanParams = {
|
|
|
25
25
|
};
|
|
26
26
|
declare const buildIdiomaticPlan: ({ src, code, exportTable, shadowedBindings, idiomaticMode, }: BuildIdiomaticPlanParams) => IdiomaticPlanResult;
|
|
27
27
|
export { buildIdiomaticPlan };
|
|
28
|
-
export type { IdiomaticPlan, IdiomaticPlanResult };
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import MagicString from 'magic-string';
|
|
2
2
|
import { type ProgramNode } from '../helpers/ast.cjs';
|
|
3
3
|
import type { FormatterOptions } from '../types.cjs';
|
|
4
|
-
declare const exportAssignment: (name: string, expr: string, live: "strict" | "loose" | "off") => string;
|
|
5
4
|
type ImportTransform = {
|
|
6
5
|
start: number;
|
|
7
6
|
end: number;
|
|
@@ -19,4 +18,4 @@ declare const lowerEsmToCjs: (program: ProgramNode, code: MagicString, opts: For
|
|
|
19
18
|
exportTransforms: ExportTransform[];
|
|
20
19
|
needsInterop: boolean;
|
|
21
20
|
};
|
|
22
|
-
export {
|
|
21
|
+
export { lowerEsmToCjs, type ExportTransform, type ImportTransform };
|
package/dist/cjs/module.cjs
CHANGED
|
@@ -5,15 +5,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.collectProjectDualPackageHazards = void 0;
|
|
7
7
|
exports.transform = transform;
|
|
8
|
-
var _nodePath = require("node:path");
|
|
9
8
|
var _promises = require("node:fs/promises");
|
|
10
|
-
var
|
|
11
|
-
var _parse = require("./parse.cjs");
|
|
9
|
+
var _nodePath = require("node:path");
|
|
12
10
|
var _format = require("./format.cjs");
|
|
11
|
+
var _parse = require("./parse.cjs");
|
|
12
|
+
var _specifier = require("./specifier.cjs");
|
|
13
|
+
var _builtinSpecifiers = require("./utils/builtinSpecifiers.cjs");
|
|
14
|
+
var _identifiers = require("./utils/identifiers.cjs");
|
|
13
15
|
var _lang = require("./utils/lang.cjs");
|
|
14
16
|
var _walk = require("./walk.cjs");
|
|
15
|
-
var _identifiers = require("./utils/identifiers.cjs");
|
|
16
|
-
var _builtinSpecifiers = require("./utils/builtinSpecifiers.cjs");
|
|
17
17
|
const collapseSpecifier = value => value.replace(/['"`+)\s]|new String\(/g, '');
|
|
18
18
|
const appendExtensionIfNeeded = (spec, mode, dirIndex, value = spec.value) => {
|
|
19
19
|
if (mode === 'off') return;
|
|
@@ -122,7 +122,8 @@ const detectCircularRequireGraph = async (entryFile, mode, dirIndex) => {
|
|
|
122
122
|
if (mode === 'error') {
|
|
123
123
|
throw new Error(msg);
|
|
124
124
|
}
|
|
125
|
-
|
|
125
|
+
|
|
126
|
+
// eslint-disable-next-line no-console
|
|
126
127
|
console.warn(msg);
|
|
127
128
|
return;
|
|
128
129
|
}
|
package/dist/cjs/module.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ModuleOptions, Diagnostic } from './types.cjs';
|
|
2
|
-
|
|
2
|
+
type SourceMap = import('magic-string').SourceMap;
|
|
3
3
|
declare const collectProjectDualPackageHazards: (files: string[], opts: ModuleOptions) => Promise<Map<string, Diagnostic[]>>;
|
|
4
4
|
declare function transform(filename: string, options: ModuleOptions & {
|
|
5
5
|
sourceMap: true;
|
|
@@ -4,8 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.buildEsmPrelude = void 0;
|
|
7
|
-
var _exports = require("../utils/exports.cjs");
|
|
8
7
|
var _interopHelpers = require("./interopHelpers.cjs");
|
|
8
|
+
var _exports = require("../utils/exports.cjs");
|
|
9
9
|
const buildEsmPrelude = options => {
|
|
10
10
|
const {
|
|
11
11
|
needsCreateRequire,
|
|
@@ -4,8 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.lowerCjsRequireToImports = exports.isStaticRequire = exports.isRequireCall = void 0;
|
|
7
|
-
var _ast = require("../helpers/ast.cjs");
|
|
8
7
|
var _interopHelpers = require("./interopHelpers.cjs");
|
|
8
|
+
var _ast = require("../helpers/ast.cjs");
|
|
9
9
|
const isRequireCallee = (callee, shadowed) => {
|
|
10
10
|
if (callee.type === 'Identifier' && callee.name === 'require' && !shadowed.has('require')) {
|
|
11
11
|
return true;
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.lowerEsmToCjs =
|
|
7
|
-
var _ast = require("../helpers/ast.cjs");
|
|
6
|
+
exports.lowerEsmToCjs = void 0;
|
|
8
7
|
var _interopHelpers = require("./interopHelpers.cjs");
|
|
8
|
+
var _ast = require("../helpers/ast.cjs");
|
|
9
9
|
const isValidIdent = name => /^[$A-Z_a-z][$\w]*$/.test(name);
|
|
10
10
|
const exportAssignment = (name, expr, live) => {
|
|
11
11
|
const prop = isValidIdent(name) ? `.${name}` : `[${JSON.stringify(name)}]`;
|
|
@@ -15,7 +15,6 @@ const exportAssignment = (name, expr, live) => {
|
|
|
15
15
|
}
|
|
16
16
|
return `exports${prop} = ${expr};`;
|
|
17
17
|
};
|
|
18
|
-
exports.exportAssignment = exportAssignment;
|
|
19
18
|
const lowerEsmToCjs = (program, code, opts, containsTopLevelAwait) => {
|
|
20
19
|
const live = opts.liveBindings ?? 'strict';
|
|
21
20
|
const importTransforms = [];
|
package/dist/cjs/specifier.cjs
CHANGED
|
@@ -4,8 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.specifier = void 0;
|
|
7
|
-
var _nodePath = require("node:path");
|
|
8
7
|
var _promises = require("node:fs/promises");
|
|
8
|
+
var _nodePath = require("node:path");
|
|
9
9
|
var _magicString = _interopRequireDefault(require("magic-string"));
|
|
10
10
|
var _oxcParser = require("oxc-parser");
|
|
11
11
|
var _walk = require("./walk.cjs");
|
package/dist/cjs/specifier.d.cts
CHANGED
|
@@ -3,10 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.exportsRename = exports.collectCjsExports = void 0;
|
|
7
7
|
var _walk = require("../walk.cjs");
|
|
8
8
|
const exportsRename = exports.exportsRename = '__exports';
|
|
9
|
-
const requireMainRgx = exports.requireMainRgx = /(require\.main\s*===\s*module|module\s*===\s*require\.main)/g;
|
|
10
9
|
const literalPropName = (prop, literals) => {
|
|
11
10
|
if (prop.type === 'Identifier') return literals?.get(prop.name)?.toString() ?? prop.name;
|
|
12
11
|
if (prop.type === 'Literal' && (typeof prop.value === 'string' || typeof prop.value === 'number')) {
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
var _walk = require("../walk.cjs");
|
|
8
|
-
var _identifier = require("../helpers/identifier.cjs");
|
|
6
|
+
exports.collectModuleIdentifiers = void 0;
|
|
9
7
|
var _scopeNodes = require("./scopeNodes.cjs");
|
|
8
|
+
var _identifier = require("../helpers/identifier.cjs");
|
|
9
|
+
var _walk = require("../walk.cjs");
|
|
10
10
|
const addBindingNames = (pattern, into) => {
|
|
11
11
|
if (!pattern) return;
|
|
12
12
|
switch (pattern.type) {
|
|
@@ -135,7 +135,6 @@ const collectScopeIdentifiers = (node, scopes) => {
|
|
|
135
135
|
* Special case handling for var inside BlockStatement
|
|
136
136
|
* which are also valid module scope identifiers.
|
|
137
137
|
*/
|
|
138
|
-
exports.collectScopeIdentifiers = collectScopeIdentifiers;
|
|
139
138
|
const collectModuleIdentifiers = async (ast, hoisting = true) => {
|
|
140
139
|
const identifiers = new Map();
|
|
141
140
|
const globalReads = new Map();
|
package/dist/cjs/walk.d.cts
CHANGED
package/dist/cli.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { readFile, mkdir, writeFile, glob } from 'node:fs/promises';
|
|
3
|
+
import { dirname, resolve, relative, join, basename } from 'node:path';
|
|
2
4
|
import { stdin as defaultStdin, stdout as defaultStdout, stderr as defaultStderr } from 'node:process';
|
|
3
5
|
import { parseArgs } from 'node:util';
|
|
4
|
-
import {
|
|
5
|
-
import { dirname, resolve, relative, join, basename } from 'node:path';
|
|
6
|
-
import { glob } from 'glob';
|
|
6
|
+
import { format } from './format.js';
|
|
7
7
|
import { transform, collectProjectDualPackageHazards } from './module.js';
|
|
8
8
|
import { parse } from './parse.js';
|
|
9
|
-
import { format } from './format.js';
|
|
10
9
|
import { specifier } from './specifier.js';
|
|
11
|
-
import { getLangFromExt } from './utils/lang.js';
|
|
12
10
|
import { builtinSpecifiers } from './utils/builtinSpecifiers.js';
|
|
11
|
+
import { getLangFromExt } from './utils/lang.js';
|
|
13
12
|
const defaultOptions = {
|
|
14
13
|
target: 'commonjs',
|
|
15
14
|
sourceType: 'auto',
|
|
@@ -381,14 +380,14 @@ const normalizeSourceMapArgv = argv => {
|
|
|
381
380
|
const expandFiles = async (patterns, cwd, ignore) => {
|
|
382
381
|
const files = new Set();
|
|
383
382
|
for (const pattern of patterns) {
|
|
384
|
-
const
|
|
383
|
+
for await (const match of glob(pattern, {
|
|
385
384
|
cwd,
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
385
|
+
exclude: ignore,
|
|
386
|
+
withFileTypes: true
|
|
387
|
+
})) {
|
|
388
|
+
if (match.isDirectory()) continue;
|
|
389
|
+
files.add(resolve(match.parentPath, match.name));
|
|
390
|
+
}
|
|
392
391
|
}
|
|
393
392
|
return [...files];
|
|
394
393
|
};
|
|
@@ -678,7 +677,7 @@ if (import.meta.main) {
|
|
|
678
677
|
runCli().then(code => {
|
|
679
678
|
if (code !== 0) process.exit(code);
|
|
680
679
|
}, err => {
|
|
681
|
-
// eslint-disable-next-line no-console
|
|
680
|
+
// eslint-disable-next-line no-console
|
|
682
681
|
console.error(err);
|
|
683
682
|
process.exit(1);
|
|
684
683
|
});
|
package/dist/exports.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import type { Node } from 'oxc-parser';
|
|
2
2
|
import type { CjsExport } from '../types.js';
|
|
3
3
|
declare const exportsRename = "__exports";
|
|
4
|
-
declare const requireMainRgx: RegExp;
|
|
5
4
|
type ExportsMap = Map<string, CjsExport> & {
|
|
6
5
|
hasUnsupportedExportWrite?: boolean;
|
|
7
6
|
};
|
|
8
7
|
declare const collectCjsExports: (ast: Node) => Promise<ExportsMap>;
|
|
9
|
-
export { exportsRename,
|
|
8
|
+
export { exportsRename, collectCjsExports };
|
package/dist/format.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { Node, ParseResult } from 'oxc-parser';
|
|
2
1
|
import MagicString from 'magic-string';
|
|
2
|
+
import type { Node, ParseResult } from 'oxc-parser';
|
|
3
3
|
import type { Diagnostic, FormatterOptions } from './types.js';
|
|
4
4
|
type HazardLevel = 'warning' | 'error';
|
|
5
|
-
|
|
5
|
+
type PackageUse = {
|
|
6
6
|
spec: string;
|
|
7
7
|
subpath: string;
|
|
8
8
|
loc?: {
|
package/dist/format.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { dirname, join, resolve as pathResolve } from 'node:path';
|
|
2
1
|
import { readFile as fsReadFile, stat as fsStat } from 'node:fs/promises';
|
|
2
|
+
import { dirname, join, resolve as pathResolve } from 'node:path';
|
|
3
3
|
import MagicString from 'magic-string';
|
|
4
|
-
import { hasTopLevelAwait, isAsyncContext } from './helpers/async.js';
|
|
5
|
-
import { isIdentifierName } from './helpers/identifier.js';
|
|
6
4
|
import { assignmentExpression } from './formatters/assignmentExpression.js';
|
|
7
5
|
import { identifier } from './formatters/identifier.js';
|
|
8
6
|
import { memberExpression } from './formatters/memberExpression.js';
|
|
9
7
|
import { metaProperty } from './formatters/metaProperty.js';
|
|
10
|
-
import {
|
|
8
|
+
import { hasTopLevelAwait, isAsyncContext } from './helpers/async.js';
|
|
9
|
+
import { isIdentifierName } from './helpers/identifier.js';
|
|
11
10
|
import { buildEsmPrelude } from './pipeline/buildEsmPrelude.js';
|
|
12
11
|
import { exportBagToEsm } from './pipeline/exportBagToEsm.js';
|
|
13
|
-
import { isRequireCall, isStaticRequire, lowerCjsRequireToImports } from './pipeline/lowerCjsRequireToImports.js';
|
|
14
|
-
import { lowerEsmToCjs } from './pipeline/lowerEsmToCjs.js';
|
|
15
12
|
import { buildFormatVisitor } from './pipeline/formatVisitor.js';
|
|
13
|
+
import { buildIdiomaticPlan } from './pipeline/idiomaticPlan.js';
|
|
16
14
|
import { interopHelper } from './pipeline/interopHelpers.js';
|
|
15
|
+
import { isRequireCall, isStaticRequire, lowerCjsRequireToImports } from './pipeline/lowerCjsRequireToImports.js';
|
|
16
|
+
import { lowerEsmToCjs } from './pipeline/lowerEsmToCjs.js';
|
|
17
|
+
import { builtinSpecifiers } from './utils/builtinSpecifiers.js';
|
|
17
18
|
import { collectCjsExports } from './utils/exports.js';
|
|
18
19
|
import { collectModuleIdentifiers } from './utils/identifiers.js';
|
|
19
20
|
import { isValidUrl } from './utils/url.js';
|
|
20
|
-
import { builtinSpecifiers } from './utils/builtinSpecifiers.js';
|
|
21
21
|
import { ancestorWalk } from './walk.js';
|
|
22
22
|
const isRequireMainMember = (node, shadowed) => node.type === 'MemberExpression' && node.object.type === 'Identifier' && node.object.name === 'require' && !shadowed.has('require') && node.property.type === 'Identifier' && node.property.name === 'main';
|
|
23
23
|
const stripQuery = value => value.includes('?') || value.includes('#') ? value.split(/[?#]/)[0] ?? value : value;
|
|
@@ -303,12 +303,12 @@ async function format(src, ast, opts) {
|
|
|
303
303
|
return;
|
|
304
304
|
}
|
|
305
305
|
if (diag.level === 'warning') {
|
|
306
|
-
// eslint-disable-next-line no-console
|
|
306
|
+
// eslint-disable-next-line no-console
|
|
307
307
|
console.warn(diag.message);
|
|
308
308
|
return;
|
|
309
309
|
}
|
|
310
310
|
|
|
311
|
-
// eslint-disable-next-line no-console
|
|
311
|
+
// eslint-disable-next-line no-console
|
|
312
312
|
console.error(diag.message);
|
|
313
313
|
};
|
|
314
314
|
const diagOnce = (level, codeId, message, loc) => {
|
package/dist/formatVisitor.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type MagicString from 'magic-string';
|
|
2
|
-
import type { Node, CallExpressionNode } from '../helpers/ast.js';
|
|
3
2
|
import type { IdentifierName } from 'oxc-parser';
|
|
4
3
|
import type { WarnOnce } from './exportBagToEsm.js';
|
|
4
|
+
import type { Node, CallExpressionNode } from '../helpers/ast.js';
|
|
5
5
|
import type { FormatterOptions, ExportsMeta } from '../types.js';
|
|
6
6
|
type AssignmentExpressionFn = (typeof import('../formatters/assignmentExpression.js'))['assignmentExpression'];
|
|
7
7
|
type IdentifierFn = (typeof import('../formatters/identifier.js'))['identifier'];
|
package/dist/helpers/ast.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type { Node } from 'oxc-parser';
|
|
2
2
|
import type { CjsExport } from '../types.js';
|
|
3
3
|
export type { Node };
|
|
4
|
-
|
|
4
|
+
type IdentifierNode = Extract<Node, {
|
|
5
5
|
type: 'Identifier';
|
|
6
6
|
}>;
|
|
7
7
|
export type LiteralNode = Extract<Node, {
|
|
8
8
|
type: 'Literal';
|
|
9
9
|
value?: unknown;
|
|
10
10
|
}>;
|
|
11
|
-
|
|
11
|
+
type MemberExpressionNode = Extract<Node, {
|
|
12
12
|
type: 'MemberExpression';
|
|
13
13
|
}>;
|
|
14
14
|
export type CallExpressionNode = Extract<Node, {
|
package/dist/helpers/async.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Node, type ProgramNode } from './ast.js';
|
|
2
2
|
declare const hasTopLevelAwait: (program: ProgramNode) => boolean;
|
|
3
3
|
declare const isAsyncContext: (ancestors: Node[]) => boolean;
|
|
4
4
|
export { hasTopLevelAwait, isAsyncContext };
|
package/dist/identifiers.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { Node } from 'oxc-parser';
|
|
2
|
-
import type { IdentMeta
|
|
3
|
-
declare const collectScopeIdentifiers: (node: Node, scopes: Scope[]) => void;
|
|
2
|
+
import type { IdentMeta } from '../types.js';
|
|
4
3
|
/**
|
|
5
4
|
* Collects all module scope identifiers in the AST.
|
|
6
5
|
*
|
|
@@ -16,4 +15,4 @@ declare const collectScopeIdentifiers: (node: Node, scopes: Scope[]) => void;
|
|
|
16
15
|
* which are also valid module scope identifiers.
|
|
17
16
|
*/
|
|
18
17
|
declare const collectModuleIdentifiers: (ast: Node, hoisting?: boolean) => Promise<Map<string, IdentMeta>>;
|
|
19
|
-
export {
|
|
18
|
+
export { collectModuleIdentifiers };
|
package/dist/idiomaticPlan.d.ts
CHANGED
|
@@ -25,4 +25,3 @@ type BuildIdiomaticPlanParams = {
|
|
|
25
25
|
};
|
|
26
26
|
declare const buildIdiomaticPlan: ({ src, code, exportTable, shadowedBindings, idiomaticMode, }: BuildIdiomaticPlanParams) => IdiomaticPlanResult;
|
|
27
27
|
export { buildIdiomaticPlan };
|
|
28
|
-
export type { IdiomaticPlan, IdiomaticPlanResult };
|
package/dist/lowerEsmToCjs.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import MagicString from 'magic-string';
|
|
2
2
|
import { type ProgramNode } from '../helpers/ast.js';
|
|
3
3
|
import type { FormatterOptions } from '../types.js';
|
|
4
|
-
declare const exportAssignment: (name: string, expr: string, live: "strict" | "loose" | "off") => string;
|
|
5
4
|
type ImportTransform = {
|
|
6
5
|
start: number;
|
|
7
6
|
end: number;
|
|
@@ -19,4 +18,4 @@ declare const lowerEsmToCjs: (program: ProgramNode, code: MagicString, opts: For
|
|
|
19
18
|
exportTransforms: ExportTransform[];
|
|
20
19
|
needsInterop: boolean;
|
|
21
20
|
};
|
|
22
|
-
export {
|
|
21
|
+
export { lowerEsmToCjs, type ExportTransform, type ImportTransform };
|
package/dist/module.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ModuleOptions, Diagnostic } from './types.js';
|
|
2
|
-
|
|
2
|
+
type SourceMap = import('magic-string').SourceMap;
|
|
3
3
|
declare const collectProjectDualPackageHazards: (files: string[], opts: ModuleOptions) => Promise<Map<string, Diagnostic[]>>;
|
|
4
4
|
declare function transform(filename: string, options: ModuleOptions & {
|
|
5
5
|
sourceMap: true;
|
package/dist/module.js
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { specifier } from './specifier.js';
|
|
4
|
-
import { parse } from './parse.js';
|
|
1
|
+
import { readFile, writeFile, stat, realpath } from 'node:fs/promises';
|
|
2
|
+
import { resolve, dirname, extname, join } from 'node:path';
|
|
5
3
|
import { format, collectDualPackageUsage, dualPackageHazardDiagnostics } from './format.js';
|
|
4
|
+
import { parse } from './parse.js';
|
|
5
|
+
import { specifier } from './specifier.js';
|
|
6
|
+
import { builtinSpecifiers } from './utils/builtinSpecifiers.js';
|
|
7
|
+
import { collectModuleIdentifiers } from './utils/identifiers.js';
|
|
6
8
|
import { getLangFromExt } from './utils/lang.js';
|
|
7
|
-
import { resolve as pathResolve, dirname as pathDirname, extname, join } from 'node:path';
|
|
8
|
-
import { readFile as fsReadFile, stat, realpath } from 'node:fs/promises';
|
|
9
|
-
import { parse as parseModule } from './parse.js';
|
|
10
9
|
import { walk } from './walk.js';
|
|
11
|
-
import { collectModuleIdentifiers } from './utils/identifiers.js';
|
|
12
|
-
import { builtinSpecifiers } from './utils/builtinSpecifiers.js';
|
|
13
10
|
const collapseSpecifier = value => value.replace(/['"`+)\s]|new String\(/g, '');
|
|
14
11
|
const appendExtensionIfNeeded = (spec, mode, dirIndex, value = spec.value) => {
|
|
15
12
|
if (mode === 'off') return;
|
|
@@ -68,10 +65,10 @@ const fileExists = async candidate => {
|
|
|
68
65
|
return false;
|
|
69
66
|
}
|
|
70
67
|
};
|
|
71
|
-
const normalizePath = async p =>
|
|
68
|
+
const normalizePath = async p => resolve(await realpath(p).catch(() => p));
|
|
72
69
|
const resolveRequirePath = async (fromFile, spec, dirIndex) => {
|
|
73
70
|
if (!spec.startsWith('./') && !spec.startsWith('../')) return null;
|
|
74
|
-
const base =
|
|
71
|
+
const base = resolve(dirname(fromFile), spec);
|
|
75
72
|
const ext = extname(base);
|
|
76
73
|
const candidates = [];
|
|
77
74
|
if (ext) {
|
|
@@ -86,8 +83,8 @@ const resolveRequirePath = async (fromFile, spec, dirIndex) => {
|
|
|
86
83
|
return null;
|
|
87
84
|
};
|
|
88
85
|
const collectStaticRequires = async (filePath, dirIndex) => {
|
|
89
|
-
const src = await
|
|
90
|
-
const ast =
|
|
86
|
+
const src = await readFile(filePath, 'utf8');
|
|
87
|
+
const ast = parse(filePath, src);
|
|
91
88
|
const specs = [];
|
|
92
89
|
await walk(ast.program, {
|
|
93
90
|
enter(node) {
|
|
@@ -118,7 +115,8 @@ const detectCircularRequireGraph = async (entryFile, mode, dirIndex) => {
|
|
|
118
115
|
if (mode === 'error') {
|
|
119
116
|
throw new Error(msg);
|
|
120
117
|
}
|
|
121
|
-
|
|
118
|
+
|
|
119
|
+
// eslint-disable-next-line no-console
|
|
122
120
|
console.warn(msg);
|
|
123
121
|
return;
|
|
124
122
|
}
|
|
@@ -158,7 +156,7 @@ const collectProjectDualPackageHazards = async (files, opts) => {
|
|
|
158
156
|
const manifestCache = new Map();
|
|
159
157
|
for (const file of files) {
|
|
160
158
|
const code = await readFile(file, 'utf8');
|
|
161
|
-
const ast =
|
|
159
|
+
const ast = parse(file, code);
|
|
162
160
|
const moduleIdentifiers = await collectModuleIdentifiers(ast.program);
|
|
163
161
|
const shadowedBindings = new Set([...moduleIdentifiers.entries()].filter(([, meta]) => meta.declare.length > 0).map(([name]) => name));
|
|
164
162
|
const perFileUsage = await collectDualPackageUsage(ast.program, shadowedBindings, file);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type MagicString from 'magic-string';
|
|
2
|
-
import type { Node, CallExpressionNode } from '../helpers/ast.js';
|
|
3
2
|
import type { IdentifierName } from 'oxc-parser';
|
|
4
3
|
import type { WarnOnce } from './exportBagToEsm.js';
|
|
4
|
+
import type { Node, CallExpressionNode } from '../helpers/ast.js';
|
|
5
5
|
import type { FormatterOptions, ExportsMeta } from '../types.js';
|
|
6
6
|
type AssignmentExpressionFn = (typeof import('../formatters/assignmentExpression.js'))['assignmentExpression'];
|
|
7
7
|
type IdentifierFn = (typeof import('../formatters/identifier.js'))['identifier'];
|
|
@@ -25,4 +25,3 @@ type BuildIdiomaticPlanParams = {
|
|
|
25
25
|
};
|
|
26
26
|
declare const buildIdiomaticPlan: ({ src, code, exportTable, shadowedBindings, idiomaticMode, }: BuildIdiomaticPlanParams) => IdiomaticPlanResult;
|
|
27
27
|
export { buildIdiomaticPlan };
|
|
28
|
-
export type { IdiomaticPlan, IdiomaticPlanResult };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { isCallExpressionNode } from '../helpers/ast.js';
|
|
2
1
|
import { requireInteropName } from './interopHelpers.js';
|
|
2
|
+
import { isCallExpressionNode } from '../helpers/ast.js';
|
|
3
3
|
const isRequireCallee = (callee, shadowed) => {
|
|
4
4
|
if (callee.type === 'Identifier' && callee.name === 'require' && !shadowed.has('require')) {
|
|
5
5
|
return true;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import MagicString from 'magic-string';
|
|
2
2
|
import { type ProgramNode } from '../helpers/ast.js';
|
|
3
3
|
import type { FormatterOptions } from '../types.js';
|
|
4
|
-
declare const exportAssignment: (name: string, expr: string, live: "strict" | "loose" | "off") => string;
|
|
5
4
|
type ImportTransform = {
|
|
6
5
|
start: number;
|
|
7
6
|
end: number;
|
|
@@ -19,4 +18,4 @@ declare const lowerEsmToCjs: (program: ProgramNode, code: MagicString, opts: For
|
|
|
19
18
|
exportTransforms: ExportTransform[];
|
|
20
19
|
needsInterop: boolean;
|
|
21
20
|
};
|
|
22
|
-
export {
|
|
21
|
+
export { lowerEsmToCjs, type ExportTransform, type ImportTransform };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { getModuleExportName } from '../helpers/ast.js';
|
|
2
1
|
import { defaultInteropName } from './interopHelpers.js';
|
|
2
|
+
import { getModuleExportName } from '../helpers/ast.js';
|
|
3
3
|
const isValidIdent = name => /^[$A-Z_a-z][$\w]*$/.test(name);
|
|
4
4
|
const exportAssignment = (name, expr, live) => {
|
|
5
5
|
const prop = isValidIdent(name) ? `.${name}` : `[${JSON.stringify(name)}]`;
|
|
@@ -194,4 +194,4 @@ const lowerEsmToCjs = (program, code, opts, containsTopLevelAwait) => {
|
|
|
194
194
|
needsInterop
|
|
195
195
|
};
|
|
196
196
|
};
|
|
197
|
-
export {
|
|
197
|
+
export { lowerEsmToCjs };
|
package/dist/specifier.d.ts
CHANGED
package/dist/specifier.js
CHANGED
package/dist/utils/exports.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import type { Node } from 'oxc-parser';
|
|
2
2
|
import type { CjsExport } from '../types.js';
|
|
3
3
|
declare const exportsRename = "__exports";
|
|
4
|
-
declare const requireMainRgx: RegExp;
|
|
5
4
|
type ExportsMap = Map<string, CjsExport> & {
|
|
6
5
|
hasUnsupportedExportWrite?: boolean;
|
|
7
6
|
};
|
|
8
7
|
declare const collectCjsExports: (ast: Node) => Promise<ExportsMap>;
|
|
9
|
-
export { exportsRename,
|
|
8
|
+
export { exportsRename, collectCjsExports };
|
package/dist/utils/exports.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ancestorWalk } from '../walk.js';
|
|
2
2
|
const exportsRename = '__exports';
|
|
3
|
-
const requireMainRgx = /(require\.main\s*===\s*module|module\s*===\s*require\.main)/g;
|
|
4
3
|
const literalPropName = (prop, literals) => {
|
|
5
4
|
if (prop.type === 'Identifier') return literals?.get(prop.name)?.toString() ?? prop.name;
|
|
6
5
|
if (prop.type === 'Literal' && (typeof prop.value === 'string' || typeof prop.value === 'number')) {
|
|
@@ -269,4 +268,4 @@ const collectCjsExports = async ast => {
|
|
|
269
268
|
exportsMap.hasUnsupportedExportWrite = hasUnsupportedExportWrite;
|
|
270
269
|
return exportsMap;
|
|
271
270
|
};
|
|
272
|
-
export { exportsRename,
|
|
271
|
+
export { exportsRename, collectCjsExports };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { Node } from 'oxc-parser';
|
|
2
|
-
import type { IdentMeta
|
|
3
|
-
declare const collectScopeIdentifiers: (node: Node, scopes: Scope[]) => void;
|
|
2
|
+
import type { IdentMeta } from '../types.js';
|
|
4
3
|
/**
|
|
5
4
|
* Collects all module scope identifiers in the AST.
|
|
6
5
|
*
|
|
@@ -16,4 +15,4 @@ declare const collectScopeIdentifiers: (node: Node, scopes: Scope[]) => void;
|
|
|
16
15
|
* which are also valid module scope identifiers.
|
|
17
16
|
*/
|
|
18
17
|
declare const collectModuleIdentifiers: (ast: Node, hoisting?: boolean) => Promise<Map<string, IdentMeta>>;
|
|
19
|
-
export {
|
|
18
|
+
export { collectModuleIdentifiers };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ancestorWalk } from '../walk.js';
|
|
2
|
-
import { identifier } from '../helpers/identifier.js';
|
|
3
1
|
import { scopeNodes } from './scopeNodes.js';
|
|
2
|
+
import { identifier } from '../helpers/identifier.js';
|
|
3
|
+
import { ancestorWalk } from '../walk.js';
|
|
4
4
|
const addBindingNames = (pattern, into) => {
|
|
5
5
|
if (!pattern) return;
|
|
6
6
|
switch (pattern.type) {
|
|
@@ -201,4 +201,4 @@ const collectModuleIdentifiers = async (ast, hoisting = true) => {
|
|
|
201
201
|
});
|
|
202
202
|
return identifiers;
|
|
203
203
|
};
|
|
204
|
-
export {
|
|
204
|
+
export { collectModuleIdentifiers };
|
package/dist/walk.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@knighted/module",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "Bidirectional transform for ES modules and CommonJS.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/module.js",
|
|
@@ -22,14 +22,17 @@
|
|
|
22
22
|
"./package.json": "./package.json"
|
|
23
23
|
},
|
|
24
24
|
"engines": {
|
|
25
|
-
"node": ">=22.21.1 <23 || >=24 <25"
|
|
25
|
+
"node": ">=22.21.1 <23 || >=24 <25 || >=26 <27"
|
|
26
26
|
},
|
|
27
27
|
"engineStrict": true,
|
|
28
28
|
"scripts": {
|
|
29
29
|
"check-types": "tsc -p tsconfig.test.json",
|
|
30
30
|
"prettier": "prettier -w .",
|
|
31
31
|
"prettier:check": "prettier -c .",
|
|
32
|
-
"lint": "oxlint --config oxlint.json .",
|
|
32
|
+
"lint:oxlint": "oxlint --config oxlint.json .",
|
|
33
|
+
"lint:eslint": "eslint src test --ext .ts",
|
|
34
|
+
"lint": "npm run lint:oxlint && npm run lint:eslint",
|
|
35
|
+
"lint:fix": "oxlint --config oxlint.json --fix . && eslint src test --ext .ts --fix",
|
|
33
36
|
"prepare": "husky",
|
|
34
37
|
"test:base": "tsx --test --test-reporter=spec",
|
|
35
38
|
"test:cli": "npm run test:base -- test/cli.ts",
|
|
@@ -64,21 +67,29 @@
|
|
|
64
67
|
"url": "https://github.com/knightedcodemonkey/module/issues"
|
|
65
68
|
},
|
|
66
69
|
"devDependencies": {
|
|
67
|
-
"@types/node": "^
|
|
68
|
-
"
|
|
70
|
+
"@types/node": "^25.9.1",
|
|
71
|
+
"@typescript-eslint/parser": "^8.59.4",
|
|
72
|
+
"babel-dual-package": "^2.0.1",
|
|
69
73
|
"c8": "^11.0.0",
|
|
74
|
+
"eslint": "^9.39.4",
|
|
75
|
+
"eslint-import-resolver-typescript": "^4.4.4",
|
|
76
|
+
"eslint-plugin-import": "^2.32.0",
|
|
70
77
|
"husky": "^9.1.7",
|
|
71
|
-
"lint-staged": "^
|
|
72
|
-
"oxlint": "^1.
|
|
78
|
+
"lint-staged": "^17.0.5",
|
|
79
|
+
"oxlint": "^1.66.0",
|
|
73
80
|
"prettier": "^3.7.4",
|
|
74
|
-
"tsx": "^4.
|
|
75
|
-
"typescript": "^
|
|
81
|
+
"tsx": "^4.22.3",
|
|
82
|
+
"typescript": "^6.0.3"
|
|
76
83
|
},
|
|
77
84
|
"dependencies": {
|
|
78
|
-
"glob": "^13.0.6",
|
|
79
85
|
"magic-string": "^0.30.21",
|
|
80
|
-
"oxc-parser": "^0.
|
|
81
|
-
"periscopic": "^4.0.
|
|
86
|
+
"oxc-parser": "^0.132.0",
|
|
87
|
+
"periscopic": "^4.0.3"
|
|
88
|
+
},
|
|
89
|
+
"overrides": {
|
|
90
|
+
"c8": {
|
|
91
|
+
"yargs": ">17.7.2 <19"
|
|
92
|
+
}
|
|
82
93
|
},
|
|
83
94
|
"prettier": {
|
|
84
95
|
"arrowParens": "avoid",
|
|
@@ -91,6 +102,7 @@
|
|
|
91
102
|
"prettier -c",
|
|
92
103
|
"oxlint --config oxlint.json"
|
|
93
104
|
],
|
|
105
|
+
"*.ts": "eslint --ext .ts",
|
|
94
106
|
"*.{json,md,yml,yaml,css,scss,html}": "prettier -c"
|
|
95
107
|
}
|
|
96
108
|
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import MagicString from 'magic-string';
|
|
2
|
-
import type { Node, ExpressionStatement } from 'oxc-parser';
|
|
3
|
-
import type { FormatterOptions } from '../types.cjs';
|
|
4
|
-
export declare const expressionStatement: (node: ExpressionStatement, parent: Node | null, src: MagicString, options: FormatterOptions) => void;
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.expressionStatement = void 0;
|
|
7
|
-
const expressionStatement = (node, parent, src, options) => {
|
|
8
|
-
if (options.target === 'module') {
|
|
9
|
-
if (node.expression.type === 'Identifier') {
|
|
10
|
-
const {
|
|
11
|
-
start,
|
|
12
|
-
end
|
|
13
|
-
} = node;
|
|
14
|
-
const name = node.expression.name;
|
|
15
|
-
|
|
16
|
-
// CommonJS globals (as bare identifiers)
|
|
17
|
-
switch (name) {
|
|
18
|
-
case 'require':
|
|
19
|
-
src.remove(start, end);
|
|
20
|
-
break;
|
|
21
|
-
case 'module':
|
|
22
|
-
src.update(start, end, 'import.meta');
|
|
23
|
-
break;
|
|
24
|
-
case 'exports':
|
|
25
|
-
src.update(start, end, '{}');
|
|
26
|
-
break;
|
|
27
|
-
case '__filename':
|
|
28
|
-
src.update(start, end, 'import.meta.filename');
|
|
29
|
-
break;
|
|
30
|
-
case '__dirname':
|
|
31
|
-
src.update(start, end, 'import.meta.dirname');
|
|
32
|
-
break;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
if (options.target === 'commonjs') {
|
|
37
|
-
if (node.expression.type === 'Identifier') {
|
|
38
|
-
const {
|
|
39
|
-
start,
|
|
40
|
-
end
|
|
41
|
-
} = node;
|
|
42
|
-
const name = node.expression.name;
|
|
43
|
-
void start;
|
|
44
|
-
void end;
|
|
45
|
-
void name;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
exports.expressionStatement = expressionStatement;
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import MagicString from 'magic-string';
|
|
2
|
-
import type { Node, ExpressionStatement } from 'oxc-parser';
|
|
3
|
-
import type { FormatterOptions } from '../types.js';
|
|
4
|
-
export declare const expressionStatement: (node: ExpressionStatement, parent: Node | null, src: MagicString, options: FormatterOptions) => void;
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import MagicString from 'magic-string';
|
|
2
|
-
import type { Node, ExpressionStatement } from 'oxc-parser';
|
|
3
|
-
import type { FormatterOptions } from '../types.js';
|
|
4
|
-
export declare const expressionStatement: (node: ExpressionStatement, parent: Node | null, src: MagicString, options: FormatterOptions) => void;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
export const expressionStatement = (node, parent, src, options) => {
|
|
2
|
-
if (options.target === 'module') {
|
|
3
|
-
if (node.expression.type === 'Identifier') {
|
|
4
|
-
const {
|
|
5
|
-
start,
|
|
6
|
-
end
|
|
7
|
-
} = node;
|
|
8
|
-
const name = node.expression.name;
|
|
9
|
-
|
|
10
|
-
// CommonJS globals (as bare identifiers)
|
|
11
|
-
switch (name) {
|
|
12
|
-
case 'require':
|
|
13
|
-
src.remove(start, end);
|
|
14
|
-
break;
|
|
15
|
-
case 'module':
|
|
16
|
-
src.update(start, end, 'import.meta');
|
|
17
|
-
break;
|
|
18
|
-
case 'exports':
|
|
19
|
-
src.update(start, end, '{}');
|
|
20
|
-
break;
|
|
21
|
-
case '__filename':
|
|
22
|
-
src.update(start, end, 'import.meta.filename');
|
|
23
|
-
break;
|
|
24
|
-
case '__dirname':
|
|
25
|
-
src.update(start, end, 'import.meta.dirname');
|
|
26
|
-
break;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
if (options.target === 'commonjs') {
|
|
31
|
-
if (node.expression.type === 'Identifier') {
|
|
32
|
-
const {
|
|
33
|
-
start,
|
|
34
|
-
end
|
|
35
|
-
} = node;
|
|
36
|
-
const name = node.expression.name;
|
|
37
|
-
void start;
|
|
38
|
-
void end;
|
|
39
|
-
void name;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
};
|