@cedarjs/vite 2.5.1 → 2.5.2-next.16
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/index.js +6 -0
- package/dist/cjs/plugins/vite-plugin-cedar-auto-import.js +107 -0
- package/dist/cjs/plugins/vite-plugin-cedar-import-dir.js +118 -0
- package/dist/cjs/plugins/vite-plugin-rsc-transform-client.js +0 -1
- package/dist/devFeServer.js +0 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/plugins/vite-plugin-cedar-auto-import.d.ts +2 -0
- package/dist/plugins/vite-plugin-cedar-auto-import.d.ts.map +1 -0
- package/dist/plugins/vite-plugin-cedar-auto-import.js +77 -0
- package/dist/plugins/vite-plugin-cedar-import-dir.d.ts +19 -0
- package/dist/plugins/vite-plugin-cedar-import-dir.d.ts.map +1 -0
- package/dist/plugins/vite-plugin-cedar-import-dir.js +84 -0
- package/dist/plugins/vite-plugin-rsc-transform-client.js +0 -1
- package/dist/runFeServer.js +0 -0
- package/package.json +11 -11
package/dist/cjs/index.js
CHANGED
|
@@ -29,9 +29,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
29
29
|
var src_exports = {};
|
|
30
30
|
__export(src_exports, {
|
|
31
31
|
cedar: () => cedar,
|
|
32
|
+
cedarAutoImportsPlugin: () => import_vite_plugin_cedar_auto_import.cedarAutoImportsPlugin,
|
|
32
33
|
cedarCellTransform: () => import_vite_plugin_cedar_cell2.cedarCellTransform,
|
|
33
34
|
cedarEntryInjectionPlugin: () => import_vite_plugin_cedar_entry_injection2.cedarEntryInjectionPlugin,
|
|
34
35
|
cedarHtmlEnvPlugin: () => import_vite_plugin_cedar_html_env2.cedarHtmlEnvPlugin,
|
|
36
|
+
cedarImportDirPlugin: () => import_vite_plugin_cedar_import_dir.cedarImportDirPlugin,
|
|
35
37
|
cedarMergedConfig: () => import_vite_plugin_merged_config2.cedarMergedConfig,
|
|
36
38
|
cedarNodePolyfills: () => import_vite_plugin_cedar_node_polyfills2.cedarNodePolyfills,
|
|
37
39
|
cedarRemoveFromBundle: () => import_vite_plugin_cedar_remove_from_bundle2.cedarRemoveFromBundle,
|
|
@@ -55,9 +57,11 @@ var import_vite_plugin_cedar_wait_for_api_server = require("./plugins/vite-plugi
|
|
|
55
57
|
var import_vite_plugin_jsx_loader = require("./plugins/vite-plugin-jsx-loader.js");
|
|
56
58
|
var import_vite_plugin_merged_config = require("./plugins/vite-plugin-merged-config.js");
|
|
57
59
|
var import_vite_plugin_swap_apollo_provider = require("./plugins/vite-plugin-swap-apollo-provider.js");
|
|
60
|
+
var import_vite_plugin_cedar_auto_import = require("./plugins/vite-plugin-cedar-auto-import.js");
|
|
58
61
|
var import_vite_plugin_cedar_cell2 = require("./plugins/vite-plugin-cedar-cell.js");
|
|
59
62
|
var import_vite_plugin_cedar_entry_injection2 = require("./plugins/vite-plugin-cedar-entry-injection.js");
|
|
60
63
|
var import_vite_plugin_cedar_html_env2 = require("./plugins/vite-plugin-cedar-html-env.js");
|
|
64
|
+
var import_vite_plugin_cedar_import_dir = require("./plugins/vite-plugin-cedar-import-dir.js");
|
|
61
65
|
var import_vite_plugin_cedar_node_polyfills2 = require("./plugins/vite-plugin-cedar-node-polyfills.js");
|
|
62
66
|
var import_vite_plugin_cedar_remove_from_bundle2 = require("./plugins/vite-plugin-cedar-remove-from-bundle.js");
|
|
63
67
|
var import_vite_plugin_cedarjs_directory_named_import = require("./plugins/vite-plugin-cedarjs-directory-named-import.js");
|
|
@@ -99,9 +103,11 @@ var src_default = cedar;
|
|
|
99
103
|
// Annotate the CommonJS export names for ESM import in node:
|
|
100
104
|
0 && (module.exports = {
|
|
101
105
|
cedar,
|
|
106
|
+
cedarAutoImportsPlugin,
|
|
102
107
|
cedarCellTransform,
|
|
103
108
|
cedarEntryInjectionPlugin,
|
|
104
109
|
cedarHtmlEnvPlugin,
|
|
110
|
+
cedarImportDirPlugin,
|
|
105
111
|
cedarMergedConfig,
|
|
106
112
|
cedarNodePolyfills,
|
|
107
113
|
cedarRemoveFromBundle,
|
|
@@ -0,0 +1,107 @@
|
|
|
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_cedar_auto_import_exports = {};
|
|
30
|
+
__export(vite_plugin_cedar_auto_import_exports, {
|
|
31
|
+
cedarAutoImportsPlugin: () => cedarAutoImportsPlugin
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(vite_plugin_cedar_auto_import_exports);
|
|
34
|
+
var import_node_path = __toESM(require("node:path"), 1);
|
|
35
|
+
var import_unplugin = __toESM(require("unimport/unplugin"), 1);
|
|
36
|
+
var import_vite = __toESM(require("unplugin-auto-import/vite"), 1);
|
|
37
|
+
var import_project_config = require("@cedarjs/project-config");
|
|
38
|
+
function cedarAutoImportsPlugin() {
|
|
39
|
+
const config = (0, import_project_config.getConfig)();
|
|
40
|
+
const cedarPaths = (0, import_project_config.getPaths)();
|
|
41
|
+
const useTrustedDocumentsGqlTag = config?.graphql?.trustedDocuments;
|
|
42
|
+
return [
|
|
43
|
+
(0, import_vite.default)({
|
|
44
|
+
// targets to transform
|
|
45
|
+
include: [
|
|
46
|
+
/web\/.*\.[tj]sx?$/,
|
|
47
|
+
// Assume we want the trusted documents gql tag import in all .jsx and
|
|
48
|
+
// .tsx files
|
|
49
|
+
/\.[tj]sx$/
|
|
50
|
+
],
|
|
51
|
+
// global imports to register
|
|
52
|
+
imports: [
|
|
53
|
+
// import gql from 'graphql-tag'
|
|
54
|
+
!useTrustedDocumentsGqlTag && {
|
|
55
|
+
"graphql-tag": ["gql"]
|
|
56
|
+
},
|
|
57
|
+
// import { gql } from 'src/graphql/gql'
|
|
58
|
+
useTrustedDocumentsGqlTag && {
|
|
59
|
+
[(0, import_project_config.importStatementPath)(
|
|
60
|
+
import_node_path.default.join(cedarPaths.web.base, "src", "graphql", "gql")
|
|
61
|
+
)]: ["gql"]
|
|
62
|
+
}
|
|
63
|
+
].filter((v) => Boolean(v)),
|
|
64
|
+
// Types aren't important since the output is ephemeral
|
|
65
|
+
dts: false
|
|
66
|
+
}),
|
|
67
|
+
(0, import_vite.default)({
|
|
68
|
+
// targets to transform
|
|
69
|
+
include: [/\.[tj]sx?$/],
|
|
70
|
+
// global imports to register
|
|
71
|
+
imports: [
|
|
72
|
+
{
|
|
73
|
+
"@cedarjs/context": ["context"]
|
|
74
|
+
}
|
|
75
|
+
],
|
|
76
|
+
// Types aren't important since the output is ephemeral
|
|
77
|
+
dts: false
|
|
78
|
+
}),
|
|
79
|
+
(0, import_vite.default)({
|
|
80
|
+
// targets to transform
|
|
81
|
+
include: [/api\/.*\.[tj]sx?$/],
|
|
82
|
+
// global imports to register
|
|
83
|
+
imports: [
|
|
84
|
+
// import gql from 'graphql-tag'
|
|
85
|
+
{
|
|
86
|
+
"graphql-tag": ["gql"]
|
|
87
|
+
}
|
|
88
|
+
],
|
|
89
|
+
// Types aren't important since the output is ephemeral
|
|
90
|
+
dts: false
|
|
91
|
+
}),
|
|
92
|
+
import_unplugin.default.vite({
|
|
93
|
+
imports: [
|
|
94
|
+
// import React from 'react'
|
|
95
|
+
{
|
|
96
|
+
name: "default",
|
|
97
|
+
as: "React",
|
|
98
|
+
from: "react"
|
|
99
|
+
}
|
|
100
|
+
]
|
|
101
|
+
})
|
|
102
|
+
];
|
|
103
|
+
}
|
|
104
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
105
|
+
0 && (module.exports = {
|
|
106
|
+
cedarAutoImportsPlugin
|
|
107
|
+
});
|
|
@@ -0,0 +1,118 @@
|
|
|
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_cedar_import_dir_exports = {};
|
|
30
|
+
__export(vite_plugin_cedar_import_dir_exports, {
|
|
31
|
+
cedarImportDirPlugin: () => cedarImportDirPlugin
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(vite_plugin_cedar_import_dir_exports);
|
|
34
|
+
var import_node_path = __toESM(require("node:path"), 1);
|
|
35
|
+
var import_napi = require("@ast-grep/napi");
|
|
36
|
+
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
37
|
+
var import_project_config = require("@cedarjs/project-config");
|
|
38
|
+
function cedarImportDirPlugin() {
|
|
39
|
+
return {
|
|
40
|
+
name: "vite-plugin-cedar-import-dir",
|
|
41
|
+
enforce: "pre",
|
|
42
|
+
async transform(code, id) {
|
|
43
|
+
if (!code.includes("/**/")) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
const ext = import_node_path.default.extname(id);
|
|
47
|
+
const language = ext === ".ts" || ext === ".tsx" ? import_napi.Lang.TypeScript : import_napi.Lang.JavaScript;
|
|
48
|
+
let ast;
|
|
49
|
+
try {
|
|
50
|
+
ast = (0, import_napi.parse)(language, code);
|
|
51
|
+
} catch (error) {
|
|
52
|
+
console.warn("Failed to parse file:", id);
|
|
53
|
+
console.warn(error);
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
const root = ast.root();
|
|
57
|
+
let hasTransformations = false;
|
|
58
|
+
const edits = [];
|
|
59
|
+
const globImports = root.findAll({
|
|
60
|
+
rule: {
|
|
61
|
+
pattern: "import $DEFAULT_IMPORT from $SOURCE"
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
for (const importNode of globImports) {
|
|
65
|
+
const sourceNode = importNode.getMatch("SOURCE");
|
|
66
|
+
const defaultImportNode = importNode.getMatch("DEFAULT_IMPORT");
|
|
67
|
+
if (!sourceNode || !defaultImportNode) {
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
const sourceValue = sourceNode.text().slice(1, -1);
|
|
71
|
+
if (!sourceValue.includes("/**/")) {
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
hasTransformations = true;
|
|
75
|
+
const importName = defaultImportNode.text();
|
|
76
|
+
const importGlob = (0, import_project_config.importStatementPath)(sourceValue);
|
|
77
|
+
const cwd = importGlob.startsWith("src/") ? (0, import_project_config.getPaths)().api.base : import_node_path.default.dirname(id);
|
|
78
|
+
try {
|
|
79
|
+
const dirFiles = import_fast_glob.default.sync(importGlob, { cwd }).filter(
|
|
80
|
+
(n) => !n.includes(".test.") && !n.includes(".scenarios.") && !n.includes(".d.ts")
|
|
81
|
+
);
|
|
82
|
+
const staticGlob = importGlob.split("*")[0];
|
|
83
|
+
const filePathToVarName = (filePath) => {
|
|
84
|
+
return filePath.replace(staticGlob, "").replace(/\.(js|ts)$/, "").replace(/[^a-zA-Z0-9]/g, "_");
|
|
85
|
+
};
|
|
86
|
+
let replacement = `let ${importName} = {};
|
|
87
|
+
`;
|
|
88
|
+
for (const filePath of dirFiles) {
|
|
89
|
+
const { dir: fileDir, name: fileName } = import_node_path.default.parse(filePath);
|
|
90
|
+
const fileImportPath = fileDir + "/" + fileName;
|
|
91
|
+
const filePathVarName = filePathToVarName(filePath);
|
|
92
|
+
const namespaceImportName = `${importName}_${filePathVarName}`;
|
|
93
|
+
replacement += `import * as ${namespaceImportName} from '${fileImportPath}';
|
|
94
|
+
`;
|
|
95
|
+
replacement += `${importName}.${filePathVarName} = ${namespaceImportName};
|
|
96
|
+
`;
|
|
97
|
+
}
|
|
98
|
+
edits.push(importNode.replace(replacement.trim()));
|
|
99
|
+
} catch (error) {
|
|
100
|
+
console.warn(`Failed to process glob import: ${sourceValue}`, error);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (hasTransformations && edits.length > 0) {
|
|
104
|
+
const transformedCode = root.commitEdits(edits);
|
|
105
|
+
return {
|
|
106
|
+
code: transformedCode,
|
|
107
|
+
map: null
|
|
108
|
+
// For simplicity, not generating source maps
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
116
|
+
0 && (module.exports = {
|
|
117
|
+
cedarImportDirPlugin
|
|
118
|
+
});
|
|
@@ -196,7 +196,6 @@ async function parseExportNamesIntoNames(code, body, names) {
|
|
|
196
196
|
async function transformClientModule(code, body, url, clientEntryFiles) {
|
|
197
197
|
const names = [];
|
|
198
198
|
await parseExportNamesIntoNames(code, body, names);
|
|
199
|
-
console.log("transformClientModule names", names);
|
|
200
199
|
const entryRecord = Object.entries(clientEntryFiles).find(
|
|
201
200
|
([_key, value]) => value === url
|
|
202
201
|
);
|
package/dist/devFeServer.js
CHANGED
|
File without changes
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { PluginOption } from 'vite';
|
|
2
|
+
export { cedarAutoImportsPlugin } from './plugins/vite-plugin-cedar-auto-import.js';
|
|
2
3
|
export { cedarCellTransform } from './plugins/vite-plugin-cedar-cell.js';
|
|
3
4
|
export { cedarEntryInjectionPlugin } from './plugins/vite-plugin-cedar-entry-injection.js';
|
|
4
5
|
export { cedarHtmlEnvPlugin } from './plugins/vite-plugin-cedar-html-env.js';
|
|
6
|
+
export { cedarImportDirPlugin } from './plugins/vite-plugin-cedar-import-dir.js';
|
|
5
7
|
export { cedarNodePolyfills } from './plugins/vite-plugin-cedar-node-polyfills.js';
|
|
6
8
|
export { cedarRemoveFromBundle } from './plugins/vite-plugin-cedar-remove-from-bundle.js';
|
|
7
9
|
export { cedarjsDirectoryNamedImportPlugin } from './plugins/vite-plugin-cedarjs-directory-named-import.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAoBxC,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAA;AACxE,OAAO,EAAE,yBAAyB,EAAE,MAAM,gDAAgD,CAAA;AAC1F,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAA;AAC5E,OAAO,EAAE,kBAAkB,EAAE,MAAM,+CAA+C,CAAA;AAClF,OAAO,EAAE,qBAAqB,EAAE,MAAM,mDAAmD,CAAA;AACzF,OAAO,EAAE,iCAAiC,EAAE,MAAM,yDAAyD,CAAA;AAC3G,OAAO,EAAE,4BAA4B,EAAE,MAAM,oDAAoD,CAAA;AACjG,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAA;AAC3E,OAAO,EAAE,iBAAiB,EAAE,MAAM,wCAAwC,CAAA;AAC1E,OAAO,EAAE,uBAAuB,EAAE,MAAM,+CAA+C,CAAA;AAEvF,KAAK,aAAa,GAAG;IACnB,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAC1B,CAAA;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,EAAE,IAAI,EAAE,GAAE,aAAkB,GAAG,YAAY,EAAE,CAsClE;AAED,8DAA8D;AAC9D,eAAe,KAAK,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAoBxC,OAAO,EAAE,sBAAsB,EAAE,MAAM,4CAA4C,CAAA;AACnF,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAA;AACxE,OAAO,EAAE,yBAAyB,EAAE,MAAM,gDAAgD,CAAA;AAC1F,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAA;AAC5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAA;AAChF,OAAO,EAAE,kBAAkB,EAAE,MAAM,+CAA+C,CAAA;AAClF,OAAO,EAAE,qBAAqB,EAAE,MAAM,mDAAmD,CAAA;AACzF,OAAO,EAAE,iCAAiC,EAAE,MAAM,yDAAyD,CAAA;AAC3G,OAAO,EAAE,4BAA4B,EAAE,MAAM,oDAAoD,CAAA;AACjG,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAA;AAC3E,OAAO,EAAE,iBAAiB,EAAE,MAAM,wCAAwC,CAAA;AAC1E,OAAO,EAAE,uBAAuB,EAAE,MAAM,+CAA+C,CAAA;AAEvF,KAAK,aAAa,GAAG;IACnB,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAC1B,CAAA;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,EAAE,IAAI,EAAE,GAAE,aAAkB,GAAG,YAAY,EAAE,CAsClE;AAED,8DAA8D;AAC9D,eAAe,KAAK,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -15,9 +15,11 @@ import { cedarWaitForApiServer } from "./plugins/vite-plugin-cedar-wait-for-api-
|
|
|
15
15
|
import { cedarTransformJsAsJsx } from "./plugins/vite-plugin-jsx-loader.js";
|
|
16
16
|
import { cedarMergedConfig } from "./plugins/vite-plugin-merged-config.js";
|
|
17
17
|
import { cedarSwapApolloProvider } from "./plugins/vite-plugin-swap-apollo-provider.js";
|
|
18
|
+
import { cedarAutoImportsPlugin } from "./plugins/vite-plugin-cedar-auto-import.js";
|
|
18
19
|
import { cedarCellTransform as cedarCellTransform2 } from "./plugins/vite-plugin-cedar-cell.js";
|
|
19
20
|
import { cedarEntryInjectionPlugin as cedarEntryInjectionPlugin2 } from "./plugins/vite-plugin-cedar-entry-injection.js";
|
|
20
21
|
import { cedarHtmlEnvPlugin as cedarHtmlEnvPlugin2 } from "./plugins/vite-plugin-cedar-html-env.js";
|
|
22
|
+
import { cedarImportDirPlugin } from "./plugins/vite-plugin-cedar-import-dir.js";
|
|
21
23
|
import { cedarNodePolyfills as cedarNodePolyfills2 } from "./plugins/vite-plugin-cedar-node-polyfills.js";
|
|
22
24
|
import { cedarRemoveFromBundle as cedarRemoveFromBundle2 } from "./plugins/vite-plugin-cedar-remove-from-bundle.js";
|
|
23
25
|
import { cedarjsDirectoryNamedImportPlugin } from "./plugins/vite-plugin-cedarjs-directory-named-import.js";
|
|
@@ -58,9 +60,11 @@ function cedar({ mode } = {}) {
|
|
|
58
60
|
var src_default = cedar;
|
|
59
61
|
export {
|
|
60
62
|
cedar,
|
|
63
|
+
cedarAutoImportsPlugin,
|
|
61
64
|
cedarCellTransform2 as cedarCellTransform,
|
|
62
65
|
cedarEntryInjectionPlugin2 as cedarEntryInjectionPlugin,
|
|
63
66
|
cedarHtmlEnvPlugin2 as cedarHtmlEnvPlugin,
|
|
67
|
+
cedarImportDirPlugin,
|
|
64
68
|
cedarMergedConfig2 as cedarMergedConfig,
|
|
65
69
|
cedarNodePolyfills2 as cedarNodePolyfills,
|
|
66
70
|
cedarRemoveFromBundle2 as cedarRemoveFromBundle,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite-plugin-cedar-auto-import.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-cedar-auto-import.ts"],"names":[],"mappings":"AAWA,wBAAgB,sBAAsB,kEA2ErC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import unimportPlugin from "unimport/unplugin";
|
|
3
|
+
import autoImport from "unplugin-auto-import/vite";
|
|
4
|
+
import {
|
|
5
|
+
getConfig,
|
|
6
|
+
getPaths,
|
|
7
|
+
importStatementPath
|
|
8
|
+
} from "@cedarjs/project-config";
|
|
9
|
+
function cedarAutoImportsPlugin() {
|
|
10
|
+
const config = getConfig();
|
|
11
|
+
const cedarPaths = getPaths();
|
|
12
|
+
const useTrustedDocumentsGqlTag = config?.graphql?.trustedDocuments;
|
|
13
|
+
return [
|
|
14
|
+
autoImport({
|
|
15
|
+
// targets to transform
|
|
16
|
+
include: [
|
|
17
|
+
/web\/.*\.[tj]sx?$/,
|
|
18
|
+
// Assume we want the trusted documents gql tag import in all .jsx and
|
|
19
|
+
// .tsx files
|
|
20
|
+
/\.[tj]sx$/
|
|
21
|
+
],
|
|
22
|
+
// global imports to register
|
|
23
|
+
imports: [
|
|
24
|
+
// import gql from 'graphql-tag'
|
|
25
|
+
!useTrustedDocumentsGqlTag && {
|
|
26
|
+
"graphql-tag": ["gql"]
|
|
27
|
+
},
|
|
28
|
+
// import { gql } from 'src/graphql/gql'
|
|
29
|
+
useTrustedDocumentsGqlTag && {
|
|
30
|
+
[importStatementPath(
|
|
31
|
+
path.join(cedarPaths.web.base, "src", "graphql", "gql")
|
|
32
|
+
)]: ["gql"]
|
|
33
|
+
}
|
|
34
|
+
].filter((v) => Boolean(v)),
|
|
35
|
+
// Types aren't important since the output is ephemeral
|
|
36
|
+
dts: false
|
|
37
|
+
}),
|
|
38
|
+
autoImport({
|
|
39
|
+
// targets to transform
|
|
40
|
+
include: [/\.[tj]sx?$/],
|
|
41
|
+
// global imports to register
|
|
42
|
+
imports: [
|
|
43
|
+
{
|
|
44
|
+
"@cedarjs/context": ["context"]
|
|
45
|
+
}
|
|
46
|
+
],
|
|
47
|
+
// Types aren't important since the output is ephemeral
|
|
48
|
+
dts: false
|
|
49
|
+
}),
|
|
50
|
+
autoImport({
|
|
51
|
+
// targets to transform
|
|
52
|
+
include: [/api\/.*\.[tj]sx?$/],
|
|
53
|
+
// global imports to register
|
|
54
|
+
imports: [
|
|
55
|
+
// import gql from 'graphql-tag'
|
|
56
|
+
{
|
|
57
|
+
"graphql-tag": ["gql"]
|
|
58
|
+
}
|
|
59
|
+
],
|
|
60
|
+
// Types aren't important since the output is ephemeral
|
|
61
|
+
dts: false
|
|
62
|
+
}),
|
|
63
|
+
unimportPlugin.vite({
|
|
64
|
+
imports: [
|
|
65
|
+
// import React from 'react'
|
|
66
|
+
{
|
|
67
|
+
name: "default",
|
|
68
|
+
as: "React",
|
|
69
|
+
from: "react"
|
|
70
|
+
}
|
|
71
|
+
]
|
|
72
|
+
})
|
|
73
|
+
];
|
|
74
|
+
}
|
|
75
|
+
export {
|
|
76
|
+
cedarAutoImportsPlugin
|
|
77
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Plugin } from 'vite';
|
|
2
|
+
/**
|
|
3
|
+
* This Vite plugin will search for import statements that include a glob double
|
|
4
|
+
* star `**` in the source part of the statement. The files that are matched are
|
|
5
|
+
* imported and appended to an object.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* Given a directory "src/services" that contains "a.js", "b.ts" and
|
|
9
|
+
* "nested/c.js" will produce the following results:
|
|
10
|
+
* ```js
|
|
11
|
+
* import services from 'src/services/**\/*.{js,ts}'
|
|
12
|
+
* console.log(services)
|
|
13
|
+
* // services.a = import('src/services/a')
|
|
14
|
+
* // services.b = import('src/services/b')
|
|
15
|
+
* // services.nested_c = import('src/services/nested/c')
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function cedarImportDirPlugin(): Plugin;
|
|
19
|
+
//# sourceMappingURL=vite-plugin-cedar-import-dir.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite-plugin-cedar-import-dir.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-cedar-import-dir.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAIlC;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,oBAAoB,IAAI,MAAM,CAgH7C"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { parse, Lang } from "@ast-grep/napi";
|
|
3
|
+
import fg from "fast-glob";
|
|
4
|
+
import { importStatementPath, getPaths } from "@cedarjs/project-config";
|
|
5
|
+
function cedarImportDirPlugin() {
|
|
6
|
+
return {
|
|
7
|
+
name: "vite-plugin-cedar-import-dir",
|
|
8
|
+
enforce: "pre",
|
|
9
|
+
async transform(code, id) {
|
|
10
|
+
if (!code.includes("/**/")) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
const ext = path.extname(id);
|
|
14
|
+
const language = ext === ".ts" || ext === ".tsx" ? Lang.TypeScript : Lang.JavaScript;
|
|
15
|
+
let ast;
|
|
16
|
+
try {
|
|
17
|
+
ast = parse(language, code);
|
|
18
|
+
} catch (error) {
|
|
19
|
+
console.warn("Failed to parse file:", id);
|
|
20
|
+
console.warn(error);
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
const root = ast.root();
|
|
24
|
+
let hasTransformations = false;
|
|
25
|
+
const edits = [];
|
|
26
|
+
const globImports = root.findAll({
|
|
27
|
+
rule: {
|
|
28
|
+
pattern: "import $DEFAULT_IMPORT from $SOURCE"
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
for (const importNode of globImports) {
|
|
32
|
+
const sourceNode = importNode.getMatch("SOURCE");
|
|
33
|
+
const defaultImportNode = importNode.getMatch("DEFAULT_IMPORT");
|
|
34
|
+
if (!sourceNode || !defaultImportNode) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
const sourceValue = sourceNode.text().slice(1, -1);
|
|
38
|
+
if (!sourceValue.includes("/**/")) {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
hasTransformations = true;
|
|
42
|
+
const importName = defaultImportNode.text();
|
|
43
|
+
const importGlob = importStatementPath(sourceValue);
|
|
44
|
+
const cwd = importGlob.startsWith("src/") ? getPaths().api.base : path.dirname(id);
|
|
45
|
+
try {
|
|
46
|
+
const dirFiles = fg.sync(importGlob, { cwd }).filter(
|
|
47
|
+
(n) => !n.includes(".test.") && !n.includes(".scenarios.") && !n.includes(".d.ts")
|
|
48
|
+
);
|
|
49
|
+
const staticGlob = importGlob.split("*")[0];
|
|
50
|
+
const filePathToVarName = (filePath) => {
|
|
51
|
+
return filePath.replace(staticGlob, "").replace(/\.(js|ts)$/, "").replace(/[^a-zA-Z0-9]/g, "_");
|
|
52
|
+
};
|
|
53
|
+
let replacement = `let ${importName} = {};
|
|
54
|
+
`;
|
|
55
|
+
for (const filePath of dirFiles) {
|
|
56
|
+
const { dir: fileDir, name: fileName } = path.parse(filePath);
|
|
57
|
+
const fileImportPath = fileDir + "/" + fileName;
|
|
58
|
+
const filePathVarName = filePathToVarName(filePath);
|
|
59
|
+
const namespaceImportName = `${importName}_${filePathVarName}`;
|
|
60
|
+
replacement += `import * as ${namespaceImportName} from '${fileImportPath}';
|
|
61
|
+
`;
|
|
62
|
+
replacement += `${importName}.${filePathVarName} = ${namespaceImportName};
|
|
63
|
+
`;
|
|
64
|
+
}
|
|
65
|
+
edits.push(importNode.replace(replacement.trim()));
|
|
66
|
+
} catch (error) {
|
|
67
|
+
console.warn(`Failed to process glob import: ${sourceValue}`, error);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (hasTransformations && edits.length > 0) {
|
|
71
|
+
const transformedCode = root.commitEdits(edits);
|
|
72
|
+
return {
|
|
73
|
+
code: transformedCode,
|
|
74
|
+
map: null
|
|
75
|
+
// For simplicity, not generating source maps
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
export {
|
|
83
|
+
cedarImportDirPlugin
|
|
84
|
+
};
|
|
@@ -163,7 +163,6 @@ async function parseExportNamesIntoNames(code, body, names) {
|
|
|
163
163
|
async function transformClientModule(code, body, url, clientEntryFiles) {
|
|
164
164
|
const names = [];
|
|
165
165
|
await parseExportNamesIntoNames(code, body, names);
|
|
166
|
-
console.log("transformClientModule names", names);
|
|
167
166
|
const entryRecord = Object.entries(clientEntryFiles).find(
|
|
168
167
|
([_key, value]) => value === url
|
|
169
168
|
);
|
package/dist/runFeServer.js
CHANGED
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/vite",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.2-next.16+a27a893fb",
|
|
4
4
|
"description": "Vite configuration package for CedarJS",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -61,17 +61,17 @@
|
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
63
|
"@ast-grep/napi": "0.40.5",
|
|
64
|
-
"@babel/generator": "7.29.
|
|
64
|
+
"@babel/generator": "7.29.1",
|
|
65
65
|
"@babel/parser": "7.29.0",
|
|
66
66
|
"@babel/traverse": "7.29.0",
|
|
67
|
-
"@cedarjs/auth": "2.5.
|
|
68
|
-
"@cedarjs/babel-config": "2.5.
|
|
69
|
-
"@cedarjs/cookie-jar": "2.5.
|
|
70
|
-
"@cedarjs/internal": "2.5.
|
|
71
|
-
"@cedarjs/project-config": "2.5.
|
|
72
|
-
"@cedarjs/server-store": "2.5.
|
|
73
|
-
"@cedarjs/testing": "2.5.
|
|
74
|
-
"@cedarjs/web": "2.5.
|
|
67
|
+
"@cedarjs/auth": "2.5.2-next.16+a27a893fb",
|
|
68
|
+
"@cedarjs/babel-config": "2.5.2-next.16+a27a893fb",
|
|
69
|
+
"@cedarjs/cookie-jar": "2.5.2-next.16+a27a893fb",
|
|
70
|
+
"@cedarjs/internal": "2.5.2-next.16+a27a893fb",
|
|
71
|
+
"@cedarjs/project-config": "2.5.2-next.16+a27a893fb",
|
|
72
|
+
"@cedarjs/server-store": "2.5.2-next.16+a27a893fb",
|
|
73
|
+
"@cedarjs/testing": "2.5.2-next.16+a27a893fb",
|
|
74
|
+
"@cedarjs/web": "2.5.2-next.16+a27a893fb",
|
|
75
75
|
"@swc/core": "1.15.11",
|
|
76
76
|
"@vitejs/plugin-react": "4.7.0",
|
|
77
77
|
"@whatwg-node/fetch": "0.10.13",
|
|
@@ -116,5 +116,5 @@
|
|
|
116
116
|
"publishConfig": {
|
|
117
117
|
"access": "public"
|
|
118
118
|
},
|
|
119
|
-
"gitHead": "
|
|
119
|
+
"gitHead": "a27a893fb8f6883f3bf121dad4d3edf7696484fe"
|
|
120
120
|
}
|