@mindees/compiler 0.27.1 → 0.28.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/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/rewrite-imports.d.ts +20 -0
- package/dist/rewrite-imports.d.ts.map +1 -0
- package/dist/rewrite-imports.js +49 -0
- package/dist/rewrite-imports.js.map +1 -0
- package/package.json +5 -2
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { PerfLintOptions, perfLint } from "./perf-lint.js";
|
|
|
3
3
|
import { CompileOptions, CompileResult, CompileStats, Diagnostic, DiagnosticSeverity, MdcPlugin, SourcePosition } from "./types.js";
|
|
4
4
|
import { BudgetOptions, checkBudget } from "./budget.js";
|
|
5
5
|
import { STATIC_MARKER, createFlattenTransformer } from "./flatten.js";
|
|
6
|
+
import { rewriteImportSpecifiers } from "./rewrite-imports.js";
|
|
6
7
|
import { GenerateRouteModuleOptions, RouteEntry, RouteManifest, buildRouteManifest, chunkName, fileToRoute, generateRouteModule } from "./routes.js";
|
|
7
8
|
import { compile, compileChecked } from "./transform.js";
|
|
8
9
|
import { hasErrors, typecheck } from "./typecheck.js";
|
|
@@ -12,7 +13,7 @@ import { Maturity, NotImplementedError, PackageInfo, notImplemented } from "@min
|
|
|
12
13
|
/** The npm package name. */
|
|
13
14
|
declare const name = "@mindees/compiler";
|
|
14
15
|
/** The package version. All `@mindees/*` packages share one locked version line. */
|
|
15
|
-
declare const VERSION = "0.
|
|
16
|
+
declare const VERSION = "0.28.0";
|
|
16
17
|
/**
|
|
17
18
|
* Current maturity. The build-time optimizer — type-check gate, TSX→createElement
|
|
18
19
|
* transform, tree-flattening, per-route manifest, plugin API — is implemented
|
|
@@ -27,5 +28,5 @@ declare const maturity: Maturity;
|
|
|
27
28
|
*/
|
|
28
29
|
declare const info: PackageInfo;
|
|
29
30
|
//#endregion
|
|
30
|
-
export { type BudgetOptions, type CompileOptions, type CompileResult, type CompileStats, type Diagnostic, type DiagnosticSeverity, type GenerateRouteModuleOptions, type Maturity, type MdcPlugin, type NativeTarget, NotImplementedError, type PackageInfo, type PerfLintOptions, type RouteEntry, type RouteManifest, STATIC_MARKER, type SourcePosition, VERSION, buildRouteManifest, checkBudget, chunkName, compile, compileChecked, compileToNative, createFlattenTransformer, fileToRoute, generateRouteModule, hasErrors, info, maturity, name, notImplemented, perfLint, typecheck };
|
|
31
|
+
export { type BudgetOptions, type CompileOptions, type CompileResult, type CompileStats, type Diagnostic, type DiagnosticSeverity, type GenerateRouteModuleOptions, type Maturity, type MdcPlugin, type NativeTarget, NotImplementedError, type PackageInfo, type PerfLintOptions, type RouteEntry, type RouteManifest, STATIC_MARKER, type SourcePosition, VERSION, buildRouteManifest, checkBudget, chunkName, compile, compileChecked, compileToNative, createFlattenTransformer, fileToRoute, generateRouteModule, hasErrors, info, maturity, name, notImplemented, perfLint, rewriteImportSpecifiers, typecheck };
|
|
31
32
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;;;;;;;;;cAuCa,IAAA;AAWb;AAAA,cARa,OAAA;;;AAQmC;AAOhD;;;cAPa,QAAA,EAAU,QAAyB;AAOoC;;;;;AAAA,cAAvE,IAAA,EAAM,WAAiE"}
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import { checkBudget } from "./budget.js";
|
|
|
3
3
|
import { STATIC_MARKER, createFlattenTransformer } from "./flatten.js";
|
|
4
4
|
import { hasErrors, typecheck } from "./typecheck.js";
|
|
5
5
|
import { perfLint } from "./perf-lint.js";
|
|
6
|
+
import { rewriteImportSpecifiers } from "./rewrite-imports.js";
|
|
6
7
|
import { buildRouteManifest, chunkName, fileToRoute, generateRouteModule } from "./routes.js";
|
|
7
8
|
import { compile, compileChecked } from "./transform.js";
|
|
8
9
|
import { NotImplementedError, notImplemented } from "@mindees/core";
|
|
@@ -10,7 +11,7 @@ import { NotImplementedError, notImplemented } from "@mindees/core";
|
|
|
10
11
|
/** The npm package name. */
|
|
11
12
|
const name = "@mindees/compiler";
|
|
12
13
|
/** The package version. All `@mindees/*` packages share one locked version line. */
|
|
13
|
-
const VERSION = "0.
|
|
14
|
+
const VERSION = "0.28.0";
|
|
14
15
|
/**
|
|
15
16
|
* Current maturity. The build-time optimizer — type-check gate, TSX→createElement
|
|
16
17
|
* transform, tree-flattening, per-route manifest, plugin API — is implemented
|
|
@@ -29,6 +30,6 @@ const info = Object.freeze({
|
|
|
29
30
|
maturity
|
|
30
31
|
});
|
|
31
32
|
//#endregion
|
|
32
|
-
export { NotImplementedError, STATIC_MARKER, VERSION, buildRouteManifest, checkBudget, chunkName, compile, compileChecked, compileToNative, createFlattenTransformer, fileToRoute, generateRouteModule, hasErrors, info, maturity, name, notImplemented, perfLint, typecheck };
|
|
33
|
+
export { NotImplementedError, STATIC_MARKER, VERSION, buildRouteManifest, checkBudget, chunkName, compile, compileChecked, compileToNative, createFlattenTransformer, fileToRoute, generateRouteModule, hasErrors, info, maturity, name, notImplemented, perfLint, rewriteImportSpecifiers, typecheck };
|
|
33
34
|
|
|
34
35
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { Maturity, PackageInfo } from '@mindees/core'\nimport { NotImplementedError, notImplemented } from '@mindees/core'\n\n/** TS → native AOT (research track). */\nexport { compileToNative, type NativeTarget } from './aot'\n/** Build-time performance budget (opt-in via `compileChecked(src, { budget })`) — fails the build. */\nexport { type BudgetOptions, checkBudget } from './budget'\n/** Tree-flattening optimizer pass. */\nexport { createFlattenTransformer, STATIC_MARKER } from './flatten'\n/** Build-time perf-lint (opt-in via `compileChecked(src, { perf: true })`). */\nexport { type PerfLintOptions, perfLint } from './perf-lint'\n/** Per-route code-splitting manifest + file-based route codegen. */\nexport {\n buildRouteManifest,\n chunkName,\n fileToRoute,\n type GenerateRouteModuleOptions,\n generateRouteModule,\n type RouteEntry,\n type RouteManifest,\n} from './routes'\n/** Compile pipeline (TSX → optimized JS). */\nexport { compile, compileChecked } from './transform'\n/** The type-check gate. */\nexport { hasErrors, typecheck } from './typecheck'\n/** Shared types. */\nexport type {\n CompileOptions,\n CompileResult,\n CompileStats,\n Diagnostic,\n DiagnosticSeverity,\n MdcPlugin,\n SourcePosition,\n} from './types'\n\n/** The npm package name. */\nexport const name = '@mindees/compiler'\n\n/** The package version. All `@mindees/*` packages share one locked version line. */\nexport const VERSION = '0.
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { Maturity, PackageInfo } from '@mindees/core'\nimport { NotImplementedError, notImplemented } from '@mindees/core'\n\n/** TS → native AOT (research track). */\nexport { compileToNative, type NativeTarget } from './aot'\n/** Build-time performance budget (opt-in via `compileChecked(src, { budget })`) — fails the build. */\nexport { type BudgetOptions, checkBudget } from './budget'\n/** Tree-flattening optimizer pass. */\nexport { createFlattenTransformer, STATIC_MARKER } from './flatten'\n/** Build-time perf-lint (opt-in via `compileChecked(src, { perf: true })`). */\nexport { type PerfLintOptions, perfLint } from './perf-lint'\n/** Rewrite relative import specifiers in emitted JS for native-ESM (browser) loading. */\nexport { rewriteImportSpecifiers } from './rewrite-imports'\n/** Per-route code-splitting manifest + file-based route codegen. */\nexport {\n buildRouteManifest,\n chunkName,\n fileToRoute,\n type GenerateRouteModuleOptions,\n generateRouteModule,\n type RouteEntry,\n type RouteManifest,\n} from './routes'\n/** Compile pipeline (TSX → optimized JS). */\nexport { compile, compileChecked } from './transform'\n/** The type-check gate. */\nexport { hasErrors, typecheck } from './typecheck'\n/** Shared types. */\nexport type {\n CompileOptions,\n CompileResult,\n CompileStats,\n Diagnostic,\n DiagnosticSeverity,\n MdcPlugin,\n SourcePosition,\n} from './types'\n\n/** The npm package name. */\nexport const name = '@mindees/compiler'\n\n/** The package version. All `@mindees/*` packages share one locked version line. */\nexport const VERSION = '0.28.0'\n\n/**\n * Current maturity. The build-time optimizer — type-check gate, TSX→createElement\n * transform, tree-flattening, per-route manifest, plugin API — is implemented\n * and tested on the TypeScript Compiler API. TS→native AOT is a research track\n * (throws `NotImplementedError`); the working path is TS → optimized JS.\n */\nexport const maturity: Maturity = 'experimental'\n\n/**\n * Static identity + maturity metadata for this package. Frozen so the\n * self-reported identity tooling introspects cannot be mutated at runtime,\n * matching the `readonly` fields of {@link PackageInfo}.\n */\nexport const info: PackageInfo = Object.freeze({ name, version: VERSION, maturity })\n\nexport type { Maturity, PackageInfo }\nexport { NotImplementedError, notImplemented }\n"],"mappings":";;;;;;;;;;;AAuCA,MAAa,OAAO;;AAGpB,MAAa,UAAU;;;;;;;AAQvB,MAAa,WAAqB;;;;;;AAOlC,MAAa,OAAoB,OAAO,OAAO;CAAE;CAAM,SAAS;CAAS;AAAS,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//#region src/rewrite-imports.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Rewrite relative import/export specifiers in EMITTED JavaScript so they load as native ES modules in a
|
|
4
|
+
* browser (which needs explicit file extensions). AST-based, not regex: it touches ONLY real module
|
|
5
|
+
* specifiers — `import … from '…'`, `export … from '…'`, and `import('…')` with a single string-literal
|
|
6
|
+
* argument. A concatenated dynamic import (`import('./x/' + name)`) has a non-literal argument and is left
|
|
7
|
+
* alone; import-like text inside a string or comment is never matched.
|
|
8
|
+
*
|
|
9
|
+
* The `resolve` callback decides the new specifier for each relative one (e.g. add `.js`, or `/index.js`
|
|
10
|
+
* for a directory). Only `./`/`../` specifiers are passed to it; bare specifiers (`@mindees/*`, npm) are
|
|
11
|
+
* left untouched. Edits are applied right-to-left so positions stay valid (minor column-level source-map
|
|
12
|
+
* drift on the edited specifiers only — never structural corruption).
|
|
13
|
+
*
|
|
14
|
+
* @module
|
|
15
|
+
*/
|
|
16
|
+
/** Rewrite relative module specifiers in `code` via `resolve`. Returns the original string if nothing changed. */
|
|
17
|
+
declare function rewriteImportSpecifiers(code: string, resolve: (specifier: string) => string): string;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { rewriteImportSpecifiers };
|
|
20
|
+
//# sourceMappingURL=rewrite-imports.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rewrite-imports.d.ts","names":[],"sources":["../src/rewrite-imports.ts"],"mappings":";;AAkBA;;;;;;;;AAEwC;;;;;;iBAFxB,uBAAA,CACd,IAAA,UACA,OAAA,GAAU,SAAA"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
//#region src/rewrite-imports.ts
|
|
3
|
+
/**
|
|
4
|
+
* Rewrite relative import/export specifiers in EMITTED JavaScript so they load as native ES modules in a
|
|
5
|
+
* browser (which needs explicit file extensions). AST-based, not regex: it touches ONLY real module
|
|
6
|
+
* specifiers — `import … from '…'`, `export … from '…'`, and `import('…')` with a single string-literal
|
|
7
|
+
* argument. A concatenated dynamic import (`import('./x/' + name)`) has a non-literal argument and is left
|
|
8
|
+
* alone; import-like text inside a string or comment is never matched.
|
|
9
|
+
*
|
|
10
|
+
* The `resolve` callback decides the new specifier for each relative one (e.g. add `.js`, or `/index.js`
|
|
11
|
+
* for a directory). Only `./`/`../` specifiers are passed to it; bare specifiers (`@mindees/*`, npm) are
|
|
12
|
+
* left untouched. Edits are applied right-to-left so positions stay valid (minor column-level source-map
|
|
13
|
+
* drift on the edited specifiers only — never structural corruption).
|
|
14
|
+
*
|
|
15
|
+
* @module
|
|
16
|
+
*/
|
|
17
|
+
/** Rewrite relative module specifiers in `code` via `resolve`. Returns the original string if nothing changed. */
|
|
18
|
+
function rewriteImportSpecifiers(code, resolve) {
|
|
19
|
+
const sf = ts.createSourceFile("module.js", code, ts.ScriptTarget.ESNext, true, ts.ScriptKind.JS);
|
|
20
|
+
const edits = [];
|
|
21
|
+
const consider = (lit) => {
|
|
22
|
+
const spec = lit.text;
|
|
23
|
+
if (!spec.startsWith("./") && !spec.startsWith("../")) return;
|
|
24
|
+
const next = resolve(spec);
|
|
25
|
+
if (next === spec) return;
|
|
26
|
+
const start = lit.getStart(sf);
|
|
27
|
+
const quote = code[start] ?? "'";
|
|
28
|
+
edits.push({
|
|
29
|
+
start,
|
|
30
|
+
end: lit.getEnd(),
|
|
31
|
+
text: `${quote}${next}${quote}`
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
const visit = (node) => {
|
|
35
|
+
if ((ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) && node.moduleSpecifier && ts.isStringLiteral(node.moduleSpecifier)) consider(node.moduleSpecifier);
|
|
36
|
+
else if (ts.isCallExpression(node) && node.expression.kind === ts.SyntaxKind.ImportKeyword && node.arguments.length === 1 && ts.isStringLiteralLike(node.arguments[0])) consider(node.arguments[0]);
|
|
37
|
+
ts.forEachChild(node, visit);
|
|
38
|
+
};
|
|
39
|
+
visit(sf);
|
|
40
|
+
if (edits.length === 0) return code;
|
|
41
|
+
edits.sort((a, b) => b.start - a.start);
|
|
42
|
+
let out = code;
|
|
43
|
+
for (const e of edits) out = out.slice(0, e.start) + e.text + out.slice(e.end);
|
|
44
|
+
return out;
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|
|
47
|
+
export { rewriteImportSpecifiers };
|
|
48
|
+
|
|
49
|
+
//# sourceMappingURL=rewrite-imports.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rewrite-imports.js","names":[],"sources":["../src/rewrite-imports.ts"],"sourcesContent":["/**\n * Rewrite relative import/export specifiers in EMITTED JavaScript so they load as native ES modules in a\n * browser (which needs explicit file extensions). AST-based, not regex: it touches ONLY real module\n * specifiers — `import … from '…'`, `export … from '…'`, and `import('…')` with a single string-literal\n * argument. A concatenated dynamic import (`import('./x/' + name)`) has a non-literal argument and is left\n * alone; import-like text inside a string or comment is never matched.\n *\n * The `resolve` callback decides the new specifier for each relative one (e.g. add `.js`, or `/index.js`\n * for a directory). Only `./`/`../` specifiers are passed to it; bare specifiers (`@mindees/*`, npm) are\n * left untouched. Edits are applied right-to-left so positions stay valid (minor column-level source-map\n * drift on the edited specifiers only — never structural corruption).\n *\n * @module\n */\n\nimport ts from 'typescript'\n\n/** Rewrite relative module specifiers in `code` via `resolve`. Returns the original string if nothing changed. */\nexport function rewriteImportSpecifiers(\n code: string,\n resolve: (specifier: string) => string,\n): string {\n const sf = ts.createSourceFile('module.js', code, ts.ScriptTarget.ESNext, true, ts.ScriptKind.JS)\n const edits: Array<{ start: number; end: number; text: string }> = []\n\n const consider = (lit: ts.StringLiteralLike): void => {\n const spec = lit.text\n if (!spec.startsWith('./') && !spec.startsWith('../')) return // only relative; bare specifiers pass through\n const next = resolve(spec)\n if (next === spec) return\n const start = lit.getStart(sf)\n const quote = code[start] ?? \"'\" // preserve the original quote character\n edits.push({ start, end: lit.getEnd(), text: `${quote}${next}${quote}` })\n }\n\n const visit = (node: ts.Node): void => {\n if (\n (ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) &&\n node.moduleSpecifier &&\n ts.isStringLiteral(node.moduleSpecifier)\n ) {\n consider(node.moduleSpecifier)\n } else if (\n ts.isCallExpression(node) &&\n node.expression.kind === ts.SyntaxKind.ImportKeyword &&\n node.arguments.length === 1 &&\n ts.isStringLiteralLike(node.arguments[0] as ts.Expression)\n ) {\n consider(node.arguments[0] as ts.StringLiteralLike)\n }\n ts.forEachChild(node, visit)\n }\n visit(sf)\n\n if (edits.length === 0) return code\n edits.sort((a, b) => b.start - a.start) // right-to-left → earlier offsets stay valid\n let out = code\n for (const e of edits) out = out.slice(0, e.start) + e.text + out.slice(e.end)\n return out\n}\n"],"mappings":";;;;;;;;;;;;;;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28.0",
|
|
4
4
|
"description": "MindeesNative Compiler (MDC) — build-time optimizer: type-check gate, TSX→createElement transform, tree-flattening, per-route code-splitting, and a plugin API. TS→native AOT is a research track.",
|
|
5
5
|
"license": "MIT OR Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=22.18.0"
|
|
9
|
+
},
|
|
7
10
|
"sideEffects": false,
|
|
8
11
|
"files": [
|
|
9
12
|
"dist"
|
|
@@ -24,7 +27,7 @@
|
|
|
24
27
|
},
|
|
25
28
|
"dependencies": {
|
|
26
29
|
"typescript": "6.0.3",
|
|
27
|
-
"@mindees/core": "0.
|
|
30
|
+
"@mindees/core": "0.28.0"
|
|
28
31
|
},
|
|
29
32
|
"scripts": {
|
|
30
33
|
"build": "tsdown",
|