@cedarjs/vite 1.0.0-canary.12378 → 1.0.0-canary.12381
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/cjs/plugins/index.js +43 -0
- package/dist/cjs/plugins/vite-plugin-cedarjs-directory-named-import.js +82 -0
- package/dist/cjs/plugins/vite-plugin-cedarjs-job-path-injector.js +152 -0
- package/dist/plugins/index.d.ts +7 -0
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/index.js +14 -0
- package/dist/plugins/vite-plugin-cedarjs-directory-named-import.d.ts +3 -0
- package/dist/plugins/vite-plugin-cedarjs-directory-named-import.d.ts.map +1 -0
- package/dist/plugins/vite-plugin-cedarjs-directory-named-import.js +48 -0
- package/dist/plugins/vite-plugin-cedarjs-job-path-injector.d.ts +3 -0
- package/dist/plugins/vite-plugin-cedarjs-job-path-injector.d.ts.map +1 -0
- package/dist/plugins/vite-plugin-cedarjs-job-path-injector.js +118 -0
- package/package.json +13 -9
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var plugins_exports = {};
|
|
20
|
+
__export(plugins_exports, {
|
|
21
|
+
cedarCellTransform: () => import_vite_plugin_cedar_cell.cedarCellTransform,
|
|
22
|
+
cedarjsDirectoryNamedImportPlugin: () => import_vite_plugin_cedarjs_directory_named_import.cedarjsDirectoryNamedImportPlugin,
|
|
23
|
+
cedarjsJobPathInjectorPlugin: () => import_vite_plugin_cedarjs_job_path_injector.cedarjsJobPathInjectorPlugin,
|
|
24
|
+
handleJsAsJsx: () => import_vite_plugin_jsx_loader.handleJsAsJsx,
|
|
25
|
+
removeFromBundle: () => import_vite_plugin_remove_from_bundle.removeFromBundle,
|
|
26
|
+
swapApolloProvider: () => import_vite_plugin_swap_apollo_provider.swapApolloProvider
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(plugins_exports);
|
|
29
|
+
var import_vite_plugin_cedar_cell = require("./vite-plugin-cedar-cell.js");
|
|
30
|
+
var import_vite_plugin_cedarjs_directory_named_import = require("./vite-plugin-cedarjs-directory-named-import.js");
|
|
31
|
+
var import_vite_plugin_cedarjs_job_path_injector = require("./vite-plugin-cedarjs-job-path-injector.js");
|
|
32
|
+
var import_vite_plugin_jsx_loader = require("./vite-plugin-jsx-loader.js");
|
|
33
|
+
var import_vite_plugin_remove_from_bundle = require("./vite-plugin-remove-from-bundle.js");
|
|
34
|
+
var import_vite_plugin_swap_apollo_provider = require("./vite-plugin-swap-apollo-provider.js");
|
|
35
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
36
|
+
0 && (module.exports = {
|
|
37
|
+
cedarCellTransform,
|
|
38
|
+
cedarjsDirectoryNamedImportPlugin,
|
|
39
|
+
cedarjsJobPathInjectorPlugin,
|
|
40
|
+
handleJsAsJsx,
|
|
41
|
+
removeFromBundle,
|
|
42
|
+
swapApolloProvider
|
|
43
|
+
});
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var vite_plugin_cedarjs_directory_named_import_exports = {};
|
|
30
|
+
__export(vite_plugin_cedarjs_directory_named_import_exports, {
|
|
31
|
+
cedarjsDirectoryNamedImportPlugin: () => cedarjsDirectoryNamedImportPlugin
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(vite_plugin_cedarjs_directory_named_import_exports);
|
|
34
|
+
var import_node_fs = __toESM(require("node:fs"), 1);
|
|
35
|
+
var import_node_path = __toESM(require("node:path"), 1);
|
|
36
|
+
var import_project_config = require("@cedarjs/project-config");
|
|
37
|
+
function getNewPath(value, filename) {
|
|
38
|
+
const dirname = import_node_path.default.dirname(value);
|
|
39
|
+
const basename = import_node_path.default.basename(value);
|
|
40
|
+
const indexImportPath = [dirname, basename, "index"].join("/");
|
|
41
|
+
const resolvedFile = (0, import_project_config.resolveFile)(
|
|
42
|
+
import_node_path.default.resolve(import_node_path.default.dirname(filename), indexImportPath)
|
|
43
|
+
);
|
|
44
|
+
if (resolvedFile) {
|
|
45
|
+
return resolvedFile;
|
|
46
|
+
} else {
|
|
47
|
+
const dirnameImportPath = [dirname, basename, basename].join("/");
|
|
48
|
+
const resolvedPath = import_node_path.default.resolve(import_node_path.default.dirname(filename), dirnameImportPath);
|
|
49
|
+
const dirnameResolvedFile = (0, import_project_config.resolveFile)(resolvedPath);
|
|
50
|
+
if (dirnameResolvedFile) {
|
|
51
|
+
return dirnameResolvedFile;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
function cedarjsDirectoryNamedImportPlugin() {
|
|
57
|
+
return {
|
|
58
|
+
name: "cedarjs-directory-named-import",
|
|
59
|
+
resolveId(id, importer) {
|
|
60
|
+
if (!importer || importer.includes("/node_modules/")) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
const resolvedPath = import_node_path.default.resolve(import_node_path.default.dirname(importer), id);
|
|
64
|
+
if (import_node_fs.default.existsSync(resolvedPath)) {
|
|
65
|
+
const stats = import_node_fs.default.statSync(resolvedPath);
|
|
66
|
+
if (stats.isFile()) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const newPath = getNewPath(id, importer);
|
|
71
|
+
if (!newPath) {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
const resolvedDirnamePath = import_node_path.default.resolve(import_node_path.default.dirname(importer), newPath);
|
|
75
|
+
return resolvedDirnamePath;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
80
|
+
0 && (module.exports = {
|
|
81
|
+
cedarjsDirectoryNamedImportPlugin
|
|
82
|
+
});
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var vite_plugin_cedarjs_job_path_injector_exports = {};
|
|
30
|
+
__export(vite_plugin_cedarjs_job_path_injector_exports, {
|
|
31
|
+
cedarjsJobPathInjectorPlugin: () => cedarjsJobPathInjectorPlugin
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(vite_plugin_cedarjs_job_path_injector_exports);
|
|
34
|
+
var import_node_path = __toESM(require("node:path"), 1);
|
|
35
|
+
var swc = __toESM(require("@swc/core"), 1);
|
|
36
|
+
var import_project_config = require("@cedarjs/project-config");
|
|
37
|
+
function cedarjsJobPathInjectorPlugin() {
|
|
38
|
+
return {
|
|
39
|
+
name: "cedarjs-job-path-injector",
|
|
40
|
+
transform(code, id) {
|
|
41
|
+
if (!code.includes("createJob")) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
const isTypescript = id.endsWith(".ts") || id.endsWith(".tsx");
|
|
45
|
+
let ast;
|
|
46
|
+
try {
|
|
47
|
+
ast = swc.parseSync(code, {
|
|
48
|
+
target: "es2022",
|
|
49
|
+
syntax: isTypescript ? "typescript" : "ecmascript",
|
|
50
|
+
tsx: id.endsWith(".tsx"),
|
|
51
|
+
jsx: id.endsWith(".jsx")
|
|
52
|
+
});
|
|
53
|
+
} catch (error) {
|
|
54
|
+
console.warn("Failed to parse file:", id);
|
|
55
|
+
console.warn(error);
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
const paths = (0, import_project_config.getPaths)();
|
|
59
|
+
let hasModifications = false;
|
|
60
|
+
const modifications = [];
|
|
61
|
+
function traverse(node) {
|
|
62
|
+
if (!node || typeof node !== "object") {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (node.type === "ExportDeclaration" && node.declaration) {
|
|
66
|
+
const declaration = node.declaration;
|
|
67
|
+
if (declaration.type === "VariableDeclaration") {
|
|
68
|
+
const declarator = declaration.declarations[0];
|
|
69
|
+
if (declarator && declarator.type === "VariableDeclarator") {
|
|
70
|
+
const init = declarator.init;
|
|
71
|
+
if (init && init.type === "CallExpression") {
|
|
72
|
+
const callee = init.callee;
|
|
73
|
+
if (callee && callee.type === "MemberExpression") {
|
|
74
|
+
const property = callee.property;
|
|
75
|
+
if (property && property.type === "Identifier" && property.value === "createJob") {
|
|
76
|
+
const variableId = declarator.id;
|
|
77
|
+
if (variableId && variableId.type === "Identifier") {
|
|
78
|
+
const importName = variableId.value;
|
|
79
|
+
const importPath = import_node_path.default.relative(paths.api.jobs, id);
|
|
80
|
+
const importPathWithoutExtension = importPath.replace(
|
|
81
|
+
/\.[^/.]+$/,
|
|
82
|
+
""
|
|
83
|
+
);
|
|
84
|
+
const firstArg = init.arguments[0];
|
|
85
|
+
if (firstArg?.expression?.type === "ObjectExpression") {
|
|
86
|
+
const objectExpr = firstArg.expression;
|
|
87
|
+
const properties = objectExpr.properties;
|
|
88
|
+
let insertPosition;
|
|
89
|
+
if (properties.length > 0) {
|
|
90
|
+
const lastProperty = properties[properties.length - 1];
|
|
91
|
+
if (lastProperty.type === "KeyValueProperty") {
|
|
92
|
+
insertPosition = lastProperty.value.span.end;
|
|
93
|
+
} else {
|
|
94
|
+
insertPosition = objectExpr.span.end - 1;
|
|
95
|
+
}
|
|
96
|
+
} else {
|
|
97
|
+
insertPosition = objectExpr.span.start + 1;
|
|
98
|
+
}
|
|
99
|
+
const pathProperty = `path: ${JSON.stringify(importPathWithoutExtension)}`;
|
|
100
|
+
const nameProperty = `name: ${JSON.stringify(importName)}`;
|
|
101
|
+
let insertText = "";
|
|
102
|
+
if (properties.length > 0) {
|
|
103
|
+
insertText = `, ${pathProperty}, ${nameProperty}`;
|
|
104
|
+
} else {
|
|
105
|
+
insertText = `${pathProperty}, ${nameProperty}`;
|
|
106
|
+
}
|
|
107
|
+
modifications.push({
|
|
108
|
+
start: insertPosition,
|
|
109
|
+
end: insertPosition,
|
|
110
|
+
replacement: insertText
|
|
111
|
+
});
|
|
112
|
+
hasModifications = true;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
for (const key in node) {
|
|
122
|
+
if (key === "parent" || key === "leadingComments" || key === "trailingComments" || key === "span") {
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
const child = node[key];
|
|
126
|
+
if (Array.isArray(child)) {
|
|
127
|
+
child.forEach(traverse);
|
|
128
|
+
} else if (child && typeof child === "object") {
|
|
129
|
+
traverse(child);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
traverse(ast);
|
|
134
|
+
if (!hasModifications) {
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
modifications.sort((a, b) => b.start - a.start);
|
|
138
|
+
let modifiedCode = code;
|
|
139
|
+
for (const mod of modifications) {
|
|
140
|
+
modifiedCode = modifiedCode.slice(0, mod.start) + mod.replacement + modifiedCode.slice(mod.end);
|
|
141
|
+
}
|
|
142
|
+
return {
|
|
143
|
+
code: modifiedCode,
|
|
144
|
+
map: null
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
150
|
+
0 && (module.exports = {
|
|
151
|
+
cedarjsJobPathInjectorPlugin
|
|
152
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { cedarCellTransform } from './vite-plugin-cedar-cell.js';
|
|
2
|
+
export { cedarjsDirectoryNamedImportPlugin } from './vite-plugin-cedarjs-directory-named-import.js';
|
|
3
|
+
export { cedarjsJobPathInjectorPlugin } from './vite-plugin-cedarjs-job-path-injector.js';
|
|
4
|
+
export { handleJsAsJsx } from './vite-plugin-jsx-loader.js';
|
|
5
|
+
export { removeFromBundle } from './vite-plugin-remove-from-bundle.js';
|
|
6
|
+
export { swapApolloProvider } from './vite-plugin-swap-apollo-provider.js';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugins/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAA;AAChE,OAAO,EAAE,iCAAiC,EAAE,MAAM,iDAAiD,CAAA;AACnG,OAAO,EAAE,4BAA4B,EAAE,MAAM,4CAA4C,CAAA;AACzF,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAA;AACtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { cedarCellTransform } from "./vite-plugin-cedar-cell.js";
|
|
2
|
+
import { cedarjsDirectoryNamedImportPlugin } from "./vite-plugin-cedarjs-directory-named-import.js";
|
|
3
|
+
import { cedarjsJobPathInjectorPlugin } from "./vite-plugin-cedarjs-job-path-injector.js";
|
|
4
|
+
import { handleJsAsJsx } from "./vite-plugin-jsx-loader.js";
|
|
5
|
+
import { removeFromBundle } from "./vite-plugin-remove-from-bundle.js";
|
|
6
|
+
import { swapApolloProvider } from "./vite-plugin-swap-apollo-provider.js";
|
|
7
|
+
export {
|
|
8
|
+
cedarCellTransform,
|
|
9
|
+
cedarjsDirectoryNamedImportPlugin,
|
|
10
|
+
cedarjsJobPathInjectorPlugin,
|
|
11
|
+
handleJsAsJsx,
|
|
12
|
+
removeFromBundle,
|
|
13
|
+
swapApolloProvider
|
|
14
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite-plugin-cedarjs-directory-named-import.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-cedarjs-directory-named-import.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAgClC,wBAAgB,iCAAiC,IAAI,MAAM,CA+B1D"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { resolveFile } from "@cedarjs/project-config";
|
|
4
|
+
function getNewPath(value, filename) {
|
|
5
|
+
const dirname = path.dirname(value);
|
|
6
|
+
const basename = path.basename(value);
|
|
7
|
+
const indexImportPath = [dirname, basename, "index"].join("/");
|
|
8
|
+
const resolvedFile = resolveFile(
|
|
9
|
+
path.resolve(path.dirname(filename), indexImportPath)
|
|
10
|
+
);
|
|
11
|
+
if (resolvedFile) {
|
|
12
|
+
return resolvedFile;
|
|
13
|
+
} else {
|
|
14
|
+
const dirnameImportPath = [dirname, basename, basename].join("/");
|
|
15
|
+
const resolvedPath = path.resolve(path.dirname(filename), dirnameImportPath);
|
|
16
|
+
const dirnameResolvedFile = resolveFile(resolvedPath);
|
|
17
|
+
if (dirnameResolvedFile) {
|
|
18
|
+
return dirnameResolvedFile;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
function cedarjsDirectoryNamedImportPlugin() {
|
|
24
|
+
return {
|
|
25
|
+
name: "cedarjs-directory-named-import",
|
|
26
|
+
resolveId(id, importer) {
|
|
27
|
+
if (!importer || importer.includes("/node_modules/")) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
const resolvedPath = path.resolve(path.dirname(importer), id);
|
|
31
|
+
if (fs.existsSync(resolvedPath)) {
|
|
32
|
+
const stats = fs.statSync(resolvedPath);
|
|
33
|
+
if (stats.isFile()) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const newPath = getNewPath(id, importer);
|
|
38
|
+
if (!newPath) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
const resolvedDirnamePath = path.resolve(path.dirname(importer), newPath);
|
|
42
|
+
return resolvedDirnamePath;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export {
|
|
47
|
+
cedarjsDirectoryNamedImportPlugin
|
|
48
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite-plugin-cedarjs-job-path-injector.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-cedarjs-job-path-injector.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAIlC,wBAAgB,4BAA4B,IAAI,MAAM,CA0KrD"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import * as swc from "@swc/core";
|
|
3
|
+
import { getPaths } from "@cedarjs/project-config";
|
|
4
|
+
function cedarjsJobPathInjectorPlugin() {
|
|
5
|
+
return {
|
|
6
|
+
name: "cedarjs-job-path-injector",
|
|
7
|
+
transform(code, id) {
|
|
8
|
+
if (!code.includes("createJob")) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
const isTypescript = id.endsWith(".ts") || id.endsWith(".tsx");
|
|
12
|
+
let ast;
|
|
13
|
+
try {
|
|
14
|
+
ast = swc.parseSync(code, {
|
|
15
|
+
target: "es2022",
|
|
16
|
+
syntax: isTypescript ? "typescript" : "ecmascript",
|
|
17
|
+
tsx: id.endsWith(".tsx"),
|
|
18
|
+
jsx: id.endsWith(".jsx")
|
|
19
|
+
});
|
|
20
|
+
} catch (error) {
|
|
21
|
+
console.warn("Failed to parse file:", id);
|
|
22
|
+
console.warn(error);
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
const paths = getPaths();
|
|
26
|
+
let hasModifications = false;
|
|
27
|
+
const modifications = [];
|
|
28
|
+
function traverse(node) {
|
|
29
|
+
if (!node || typeof node !== "object") {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (node.type === "ExportDeclaration" && node.declaration) {
|
|
33
|
+
const declaration = node.declaration;
|
|
34
|
+
if (declaration.type === "VariableDeclaration") {
|
|
35
|
+
const declarator = declaration.declarations[0];
|
|
36
|
+
if (declarator && declarator.type === "VariableDeclarator") {
|
|
37
|
+
const init = declarator.init;
|
|
38
|
+
if (init && init.type === "CallExpression") {
|
|
39
|
+
const callee = init.callee;
|
|
40
|
+
if (callee && callee.type === "MemberExpression") {
|
|
41
|
+
const property = callee.property;
|
|
42
|
+
if (property && property.type === "Identifier" && property.value === "createJob") {
|
|
43
|
+
const variableId = declarator.id;
|
|
44
|
+
if (variableId && variableId.type === "Identifier") {
|
|
45
|
+
const importName = variableId.value;
|
|
46
|
+
const importPath = path.relative(paths.api.jobs, id);
|
|
47
|
+
const importPathWithoutExtension = importPath.replace(
|
|
48
|
+
/\.[^/.]+$/,
|
|
49
|
+
""
|
|
50
|
+
);
|
|
51
|
+
const firstArg = init.arguments[0];
|
|
52
|
+
if (firstArg?.expression?.type === "ObjectExpression") {
|
|
53
|
+
const objectExpr = firstArg.expression;
|
|
54
|
+
const properties = objectExpr.properties;
|
|
55
|
+
let insertPosition;
|
|
56
|
+
if (properties.length > 0) {
|
|
57
|
+
const lastProperty = properties[properties.length - 1];
|
|
58
|
+
if (lastProperty.type === "KeyValueProperty") {
|
|
59
|
+
insertPosition = lastProperty.value.span.end;
|
|
60
|
+
} else {
|
|
61
|
+
insertPosition = objectExpr.span.end - 1;
|
|
62
|
+
}
|
|
63
|
+
} else {
|
|
64
|
+
insertPosition = objectExpr.span.start + 1;
|
|
65
|
+
}
|
|
66
|
+
const pathProperty = `path: ${JSON.stringify(importPathWithoutExtension)}`;
|
|
67
|
+
const nameProperty = `name: ${JSON.stringify(importName)}`;
|
|
68
|
+
let insertText = "";
|
|
69
|
+
if (properties.length > 0) {
|
|
70
|
+
insertText = `, ${pathProperty}, ${nameProperty}`;
|
|
71
|
+
} else {
|
|
72
|
+
insertText = `${pathProperty}, ${nameProperty}`;
|
|
73
|
+
}
|
|
74
|
+
modifications.push({
|
|
75
|
+
start: insertPosition,
|
|
76
|
+
end: insertPosition,
|
|
77
|
+
replacement: insertText
|
|
78
|
+
});
|
|
79
|
+
hasModifications = true;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
for (const key in node) {
|
|
89
|
+
if (key === "parent" || key === "leadingComments" || key === "trailingComments" || key === "span") {
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
const child = node[key];
|
|
93
|
+
if (Array.isArray(child)) {
|
|
94
|
+
child.forEach(traverse);
|
|
95
|
+
} else if (child && typeof child === "object") {
|
|
96
|
+
traverse(child);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
traverse(ast);
|
|
101
|
+
if (!hasModifications) {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
modifications.sort((a, b) => b.start - a.start);
|
|
105
|
+
let modifiedCode = code;
|
|
106
|
+
for (const mod of modifications) {
|
|
107
|
+
modifiedCode = modifiedCode.slice(0, mod.start) + mod.replacement + modifiedCode.slice(mod.end);
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
code: modifiedCode,
|
|
111
|
+
map: null
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
export {
|
|
117
|
+
cedarjsJobPathInjectorPlugin
|
|
118
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/vite",
|
|
3
|
-
"version": "1.0.0-canary.
|
|
3
|
+
"version": "1.0.0-canary.12381+f68e0d2f6",
|
|
4
4
|
"description": "Vite configuration package for CedarJS",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -33,6 +33,10 @@
|
|
|
33
33
|
"import": "./dist/build/build.js",
|
|
34
34
|
"default": "./dist/cjs/build/build.js"
|
|
35
35
|
},
|
|
36
|
+
"./plugins": {
|
|
37
|
+
"import": "./dist/plugins/index.js",
|
|
38
|
+
"default": "./dist/cjs/plugins/index.js"
|
|
39
|
+
},
|
|
36
40
|
"./bins/rw-vite-build.mjs": "./bins/rw-vite-build.mjs"
|
|
37
41
|
},
|
|
38
42
|
"bin": {
|
|
@@ -59,13 +63,13 @@
|
|
|
59
63
|
"@babel/generator": "7.27.5",
|
|
60
64
|
"@babel/parser": "7.27.5",
|
|
61
65
|
"@babel/traverse": "7.27.4",
|
|
62
|
-
"@cedarjs/auth": "1.0.0-canary.
|
|
63
|
-
"@cedarjs/babel-config": "1.0.0-canary.
|
|
64
|
-
"@cedarjs/cookie-jar": "1.0.0-canary.
|
|
65
|
-
"@cedarjs/internal": "1.0.0-canary.
|
|
66
|
-
"@cedarjs/project-config": "1.0.0-canary.
|
|
67
|
-
"@cedarjs/server-store": "1.0.0-canary.
|
|
68
|
-
"@cedarjs/web": "1.0.0-canary.
|
|
66
|
+
"@cedarjs/auth": "1.0.0-canary.12381",
|
|
67
|
+
"@cedarjs/babel-config": "1.0.0-canary.12381",
|
|
68
|
+
"@cedarjs/cookie-jar": "1.0.0-canary.12381",
|
|
69
|
+
"@cedarjs/internal": "1.0.0-canary.12381",
|
|
70
|
+
"@cedarjs/project-config": "1.0.0-canary.12381",
|
|
71
|
+
"@cedarjs/server-store": "1.0.0-canary.12381",
|
|
72
|
+
"@cedarjs/web": "1.0.0-canary.12381",
|
|
69
73
|
"@swc/core": "1.12.1",
|
|
70
74
|
"@vitejs/plugin-react": "4.3.4",
|
|
71
75
|
"@whatwg-node/fetch": "0.9.21",
|
|
@@ -109,5 +113,5 @@
|
|
|
109
113
|
"typescript": "5.6.2",
|
|
110
114
|
"vitest": "3.2.4"
|
|
111
115
|
},
|
|
112
|
-
"gitHead": "
|
|
116
|
+
"gitHead": "f68e0d2f6cc27c9b25edf9f3d6d7bb7b316e4247"
|
|
113
117
|
}
|