xanix 1.0.12 → 1.0.13
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/bin/bundler/plugins/XanixTsconfigAlias.js +14 -21
- package/package.json +4 -4
- package/dist/bin/bundler/cacheNpmModules copy.d.ts +0 -11
- package/dist/bin/bundler/cacheNpmModules copy.js +0 -162
- package/dist/bin/bundler/plugins/XanixPageTransform.d.ts +0 -0
- package/dist/bin/bundler/plugins/XanixPageTransform.js +0 -1
- package/dist/bin/bundler/plugins/XanixTransform/index.d.ts +0 -2
- package/dist/bin/bundler/plugins/XanixTransform/index.js +0 -19
- package/dist/bin/bundler/plugins/XanixTransform/transformer copy.d.ts +0 -16
- package/dist/bin/bundler/plugins/XanixTransform/transformer copy.js +0 -631
- package/dist/bin/bundler/plugins/XanixTransform/transformer.d.ts +0 -16
- package/dist/bin/bundler/plugins/XanixTransform/transformer.js +0 -501
- package/dist/dirs.d.ts +0 -0
- package/dist/dirs.js +0 -1
- package/dist/outdir.d.ts +0 -8
- package/dist/outdir.js +0 -9
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import alias from "@rollup/plugin-alias";
|
|
4
|
+
import ts from "typescript";
|
|
4
5
|
export default function xanixTsconfigAlias() {
|
|
5
6
|
const root = process.cwd();
|
|
6
7
|
const tsconfigPath = path.resolve(root, "tsconfig.json");
|
|
@@ -9,14 +10,12 @@ export default function xanixTsconfigAlias() {
|
|
|
9
10
|
name: "xanix-tsconfig-alias",
|
|
10
11
|
};
|
|
11
12
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
catch (error) {
|
|
18
|
-
throw new Error(`[xanix] Failed to read tsconfig.json:\n${error.message}`);
|
|
13
|
+
const result = ts.readConfigFile(tsconfigPath, ts.sys.readFile);
|
|
14
|
+
if (result.error) {
|
|
15
|
+
const message = ts.flattenDiagnosticMessageText(result.error.messageText, "\n");
|
|
16
|
+
throw new Error(`[xanix] Failed to read tsconfig.json:\n${message}`);
|
|
19
17
|
}
|
|
18
|
+
const config = result.config;
|
|
20
19
|
const compilerOptions = config.compilerOptions ?? {};
|
|
21
20
|
const baseUrl = compilerOptions.baseUrl ?? ".";
|
|
22
21
|
const basePath = path.resolve(path.dirname(tsconfigPath), baseUrl);
|
|
@@ -26,20 +25,24 @@ export default function xanixTsconfigAlias() {
|
|
|
26
25
|
const replacement = replacements?.[0];
|
|
27
26
|
if (!replacement)
|
|
28
27
|
return null;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const
|
|
28
|
+
// @components/*
|
|
29
|
+
if (find.endsWith("/*")) {
|
|
30
|
+
const findPrefix = find.slice(0, -2);
|
|
31
|
+
const replacementPrefix = replacement.endsWith("/*")
|
|
32
|
+
? replacement.slice(0, -2)
|
|
33
|
+
: replacement;
|
|
32
34
|
return {
|
|
33
35
|
find: new RegExp(`^${escapeRegExp(findPrefix)}/(.+)$`),
|
|
34
36
|
replacement: `${path.resolve(basePath, replacementPrefix)}/$1`,
|
|
35
37
|
};
|
|
36
38
|
}
|
|
39
|
+
// @foo
|
|
37
40
|
return {
|
|
38
41
|
find,
|
|
39
42
|
replacement: path.resolve(basePath, replacement),
|
|
40
43
|
};
|
|
41
44
|
})
|
|
42
|
-
.filter(
|
|
45
|
+
.filter((entry) => entry !== null);
|
|
43
46
|
return alias({
|
|
44
47
|
entries,
|
|
45
48
|
});
|
|
@@ -47,13 +50,3 @@ export default function xanixTsconfigAlias() {
|
|
|
47
50
|
function escapeRegExp(value) {
|
|
48
51
|
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
49
52
|
}
|
|
50
|
-
function parseJsonc(content) {
|
|
51
|
-
const withoutComments = content
|
|
52
|
-
// Remove /* block comments */
|
|
53
|
-
.replace(/\/\*[\s\S]*?\*\//g, "")
|
|
54
|
-
// Remove // comments
|
|
55
|
-
.replace(/\/\/.*$/gm, "");
|
|
56
|
-
// Remove trailing commas
|
|
57
|
-
const withoutTrailingCommas = withoutComments.replace(/,\s*([}\]])/g, "$1");
|
|
58
|
-
return JSON.parse(withoutTrailingCommas);
|
|
59
|
-
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xanix",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.13",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -52,7 +52,8 @@
|
|
|
52
52
|
"rollup": "^4.62.5",
|
|
53
53
|
"rollup-plugin-esbuild": "^6.2.1",
|
|
54
54
|
"tslib": "^2.8.1",
|
|
55
|
-
"ws": "^8.21.3"
|
|
55
|
+
"ws": "^8.21.3",
|
|
56
|
+
"typescript": "^5.9.3"
|
|
56
57
|
},
|
|
57
58
|
"devDependencies": {
|
|
58
59
|
"@types/babel__core": "^7.20.5",
|
|
@@ -67,7 +68,6 @@
|
|
|
67
68
|
"@xanui/icons": "^1.1.14",
|
|
68
69
|
"@xanui/ui": "^1.2.24",
|
|
69
70
|
"react": "^19.2.8",
|
|
70
|
-
"react-dom": "^19.2.8"
|
|
71
|
-
"typescript": "^5.9.3"
|
|
71
|
+
"react-dom": "^19.2.8"
|
|
72
72
|
}
|
|
73
73
|
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { XanixClientEntry } from "../types";
|
|
2
|
-
export type DependencyInfo = {
|
|
3
|
-
source: string;
|
|
4
|
-
resolved: string;
|
|
5
|
-
packageName: string;
|
|
6
|
-
};
|
|
7
|
-
export type CacheMetadata = Map<string, {
|
|
8
|
-
file: string;
|
|
9
|
-
}>;
|
|
10
|
-
declare const BuildCache: (entries: XanixClientEntry[]) => Promise<CacheMetadata>;
|
|
11
|
-
export default BuildCache;
|
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
import { rollup } from "rollup";
|
|
3
|
-
import { nodeResolve } from "@rollup/plugin-node-resolve";
|
|
4
|
-
import { build } from "esbuild";
|
|
5
|
-
import { createRequire } from "node:module";
|
|
6
|
-
import { getClientRuntimeFile, getDocumentFile } from "../include/utils.js";
|
|
7
|
-
import esbuild from "rollup-plugin-esbuild";
|
|
8
|
-
import url from "@rollup/plugin-url";
|
|
9
|
-
import XanixDocument from "./plugins/XanixDocument/index.js";
|
|
10
|
-
const require = createRequire(import.meta.url);
|
|
11
|
-
const GenerateGraph = async (entries) => {
|
|
12
|
-
const collector = new Map();
|
|
13
|
-
const input = [];
|
|
14
|
-
for (const entry of entries) {
|
|
15
|
-
input.push(entry.file);
|
|
16
|
-
}
|
|
17
|
-
input.push(getClientRuntimeFile());
|
|
18
|
-
input.push(await getDocumentFile());
|
|
19
|
-
const bundle = await rollup({
|
|
20
|
-
input,
|
|
21
|
-
plugins: [
|
|
22
|
-
nodeResolve({
|
|
23
|
-
extensions: [".mjs", ".js", ".jsx", ".json", ".ts", ".tsx"],
|
|
24
|
-
}),
|
|
25
|
-
url({
|
|
26
|
-
include: [
|
|
27
|
-
"**/*.jpg",
|
|
28
|
-
"**/*.jpeg",
|
|
29
|
-
"**/*.png",
|
|
30
|
-
"**/*.gif",
|
|
31
|
-
"**/*.webp",
|
|
32
|
-
"**/*.svg",
|
|
33
|
-
"**/*.ico",
|
|
34
|
-
"**/*.woff",
|
|
35
|
-
"**/*.woff2",
|
|
36
|
-
"**/*.ttf",
|
|
37
|
-
"**/*.eot",
|
|
38
|
-
"**/*.css",
|
|
39
|
-
],
|
|
40
|
-
limit: 0,
|
|
41
|
-
fileName: "assets/[name]-[hash][extname]",
|
|
42
|
-
emitFiles: false,
|
|
43
|
-
}),
|
|
44
|
-
XanixDocument(),
|
|
45
|
-
esbuild({
|
|
46
|
-
target: "es2022",
|
|
47
|
-
jsx: "automatic",
|
|
48
|
-
tsconfig: false,
|
|
49
|
-
}),
|
|
50
|
-
],
|
|
51
|
-
external(id) {
|
|
52
|
-
if (id.startsWith(".") ||
|
|
53
|
-
path.isAbsolute(id) ||
|
|
54
|
-
id === "@" ||
|
|
55
|
-
id.startsWith("@/") ||
|
|
56
|
-
id === "virtual:xanix-document") {
|
|
57
|
-
return false;
|
|
58
|
-
}
|
|
59
|
-
collector.set(id, {
|
|
60
|
-
source: id,
|
|
61
|
-
resolved: require.resolve(id, {
|
|
62
|
-
paths: [process.cwd()],
|
|
63
|
-
}),
|
|
64
|
-
packageName: id,
|
|
65
|
-
});
|
|
66
|
-
return true;
|
|
67
|
-
},
|
|
68
|
-
});
|
|
69
|
-
await bundle.close();
|
|
70
|
-
return collector;
|
|
71
|
-
};
|
|
72
|
-
// Wraps each CJS dep in a virtual ESM file that re-exports named exports detected via require()
|
|
73
|
-
const makeCjsWrapperPlugin = (wrappers) => ({
|
|
74
|
-
name: "cjs-named-exports",
|
|
75
|
-
setup(build) {
|
|
76
|
-
build.onResolve({ filter: /\?cjs-wrapper$/ }, (args) => ({
|
|
77
|
-
path: args.path,
|
|
78
|
-
namespace: "cjs-wrapper",
|
|
79
|
-
}));
|
|
80
|
-
build.onLoad({ filter: /.*/, namespace: "cjs-wrapper" }, (args) => {
|
|
81
|
-
const contents = wrappers.get(args.path);
|
|
82
|
-
return { contents, resolveDir: process.cwd() };
|
|
83
|
-
});
|
|
84
|
-
},
|
|
85
|
-
});
|
|
86
|
-
const buildWrappers = (input) => {
|
|
87
|
-
const wrappers = new Map();
|
|
88
|
-
const wrappedInput = {};
|
|
89
|
-
for (const [name, resolved] of Object.entries(input)) {
|
|
90
|
-
const key = `${name}?cjs-wrapper`;
|
|
91
|
-
let namedExports = [];
|
|
92
|
-
let hasDefault = false;
|
|
93
|
-
try {
|
|
94
|
-
const mod = require(resolved);
|
|
95
|
-
hasDefault =
|
|
96
|
-
mod &&
|
|
97
|
-
(typeof mod === "object" || typeof mod === "function") &&
|
|
98
|
-
"default" in mod;
|
|
99
|
-
namedExports = Object.keys(mod).filter((key) => key !== "__esModule" && key !== "default");
|
|
100
|
-
}
|
|
101
|
-
catch (err) {
|
|
102
|
-
// console.log(err);
|
|
103
|
-
}
|
|
104
|
-
const lines = [`import * as __mod from ${JSON.stringify(resolved)};`];
|
|
105
|
-
if (hasDefault) {
|
|
106
|
-
lines.push(`export default __mod.default;`);
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
lines.push(`export default __mod;`);
|
|
110
|
-
}
|
|
111
|
-
lines.push("");
|
|
112
|
-
for (const exportName of namedExports) {
|
|
113
|
-
if (/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(exportName)) {
|
|
114
|
-
lines.push(`export const ${exportName} = __mod[${JSON.stringify(exportName)}];`);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
wrappers.set(key, lines.join("\n"));
|
|
118
|
-
wrappedInput[name] = key;
|
|
119
|
-
}
|
|
120
|
-
return {
|
|
121
|
-
wrappers,
|
|
122
|
-
wrappedInput,
|
|
123
|
-
};
|
|
124
|
-
};
|
|
125
|
-
const bundleDeps = async (input, outdir) => {
|
|
126
|
-
const { wrappers, wrappedInput } = buildWrappers(input);
|
|
127
|
-
await build({
|
|
128
|
-
entryPoints: wrappedInput,
|
|
129
|
-
bundle: true,
|
|
130
|
-
splitting: true,
|
|
131
|
-
format: "esm",
|
|
132
|
-
target: "es2022",
|
|
133
|
-
outdir,
|
|
134
|
-
entryNames: "[name]",
|
|
135
|
-
chunkNames: "chunks/[hash]",
|
|
136
|
-
platform: "browser",
|
|
137
|
-
sourcemap: true,
|
|
138
|
-
define: {
|
|
139
|
-
__XANIX_CLIENT__: "true",
|
|
140
|
-
__XANIX_SERVER__: "false",
|
|
141
|
-
__XANIX_DEV__: "true",
|
|
142
|
-
__XANIX_PROD__: "false",
|
|
143
|
-
},
|
|
144
|
-
plugins: [makeCjsWrapperPlugin(wrappers)],
|
|
145
|
-
});
|
|
146
|
-
};
|
|
147
|
-
const metadata = new Map();
|
|
148
|
-
const BuildCache = async (entries) => {
|
|
149
|
-
const input = {};
|
|
150
|
-
const dependencies = await GenerateGraph(entries);
|
|
151
|
-
for (const dependency of dependencies.values()) {
|
|
152
|
-
const entryName = dependency.source.replace(/^@/, "").replace(/\//g, "-");
|
|
153
|
-
input[entryName] = dependency.resolved;
|
|
154
|
-
metadata.set(dependency.source, {
|
|
155
|
-
file: `${entryName}.js`,
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
const cacheDir = path.resolve(process.cwd(), ".xanix/cache");
|
|
159
|
-
await bundleDeps(input, cacheDir);
|
|
160
|
-
return metadata;
|
|
161
|
-
};
|
|
162
|
-
export default BuildCache;
|
|
File without changes
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { transformer } from "./transformer.js";
|
|
2
|
-
export function XanixTransform() {
|
|
3
|
-
return {
|
|
4
|
-
name: "xanix-transform",
|
|
5
|
-
async transform(code, id) {
|
|
6
|
-
if (id.includes("node_modules") || !/\.(tsx?|jsx?)$/.test(id)) {
|
|
7
|
-
return null;
|
|
8
|
-
}
|
|
9
|
-
const result = transformer(code, id);
|
|
10
|
-
if (!result) {
|
|
11
|
-
return null;
|
|
12
|
-
}
|
|
13
|
-
return {
|
|
14
|
-
code: result.code,
|
|
15
|
-
map: result.map,
|
|
16
|
-
};
|
|
17
|
-
},
|
|
18
|
-
};
|
|
19
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import * as t from "@babel/types";
|
|
2
|
-
export interface XanixTransformResult {
|
|
3
|
-
code: string;
|
|
4
|
-
map: any;
|
|
5
|
-
}
|
|
6
|
-
export declare function resolveFile(file: string): string;
|
|
7
|
-
export declare function resolveComponentFile(importer: string, importPath: string): string;
|
|
8
|
-
export declare function createPageId(file: string): string;
|
|
9
|
-
export declare function getJSXComponentName(node: t.JSXElement): string | null;
|
|
10
|
-
export declare function findComponentImport(ast: t.File, componentName: string): {
|
|
11
|
-
file: string;
|
|
12
|
-
export: string;
|
|
13
|
-
declaration: t.ImportDeclaration;
|
|
14
|
-
specifier: t.ImportSpecifier | t.ImportDefaultSpecifier;
|
|
15
|
-
} | null;
|
|
16
|
-
export declare function transformer(code: string, id: string, mode: "watch" | "start"): XanixTransformResult | null;
|