sb-mig 6.0.0-beta.5 → 6.0.0-beta.6
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.
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export declare const _extractComponentName: (filePath: string) => string;
|
|
2
2
|
interface BuildOnTheFly {
|
|
3
3
|
files: string[];
|
|
4
|
+
projectDir?: string;
|
|
4
5
|
}
|
|
5
|
-
export declare const buildOnTheFly: ({ files }: BuildOnTheFly) => Promise<void>;
|
|
6
|
+
export declare const buildOnTheFly: ({ files, projectDir, }: BuildOnTheFly) => Promise<void>;
|
|
6
7
|
export {};
|
|
@@ -1,17 +1,89 @@
|
|
|
1
|
+
import { existsSync, statSync } from "fs";
|
|
1
2
|
import path from "path";
|
|
3
|
+
import { nodeResolve } from "@rollup/plugin-node-resolve";
|
|
2
4
|
import rollupSwc from "@rollup/plugin-swc";
|
|
3
5
|
import { remove } from "fs-extra";
|
|
6
|
+
import ts from "typescript";
|
|
4
7
|
import storyblokConfig from "../config/config.js";
|
|
5
8
|
import Logger from "../utils/logger.js";
|
|
6
9
|
import { extractComponentName } from "../utils/path-utils.js";
|
|
7
10
|
import { build } from "./setup-rollup.js";
|
|
8
11
|
// Re-export for backward compatibility
|
|
9
12
|
export const _extractComponentName = extractComponentName;
|
|
10
|
-
|
|
13
|
+
const RESOLVE_EXTENSIONS = [".mjs", ".js", ".cjs", ".ts", ".tsx", ".json"];
|
|
14
|
+
const getExistingFile = (filePath) => {
|
|
15
|
+
const candidates = [
|
|
16
|
+
filePath,
|
|
17
|
+
...RESOLVE_EXTENSIONS.map((extension) => `${filePath}${extension}`),
|
|
18
|
+
...RESOLVE_EXTENSIONS.map((extension) => path.join(filePath, `index${extension}`)),
|
|
19
|
+
];
|
|
20
|
+
for (const candidate of candidates) {
|
|
21
|
+
try {
|
|
22
|
+
if (existsSync(candidate) && statSync(candidate).isFile()) {
|
|
23
|
+
return candidate;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
// Ignore inaccessible candidates and continue resolving.
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return null;
|
|
31
|
+
};
|
|
32
|
+
const getTsconfigCompilerOptions = (projectDir) => {
|
|
33
|
+
const configPath = ts.findConfigFile(projectDir, ts.sys.fileExists);
|
|
34
|
+
if (!configPath) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
|
|
38
|
+
if (configFile.error) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
const parsed = ts.parseJsonConfigFileContent(configFile.config, ts.sys, path.dirname(configPath));
|
|
42
|
+
return parsed.options;
|
|
43
|
+
};
|
|
44
|
+
const matchTsconfigPathPattern = (source, pattern) => {
|
|
45
|
+
const wildcardIndex = pattern.indexOf("*");
|
|
46
|
+
if (wildcardIndex === -1) {
|
|
47
|
+
return source === pattern ? "" : null;
|
|
48
|
+
}
|
|
49
|
+
const prefix = pattern.slice(0, wildcardIndex);
|
|
50
|
+
const suffix = pattern.slice(wildcardIndex + 1);
|
|
51
|
+
if (!source.startsWith(prefix) || !source.endsWith(suffix)) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
return source.slice(prefix.length, source.length - suffix.length);
|
|
55
|
+
};
|
|
56
|
+
const createTsconfigPathsResolver = (projectDir) => {
|
|
57
|
+
const compilerOptions = getTsconfigCompilerOptions(projectDir);
|
|
58
|
+
const paths = compilerOptions?.paths;
|
|
59
|
+
const baseUrl = compilerOptions?.baseUrl ?? projectDir;
|
|
60
|
+
return {
|
|
61
|
+
name: "sb-mig-tsconfig-paths",
|
|
62
|
+
resolveId(source) {
|
|
63
|
+
if (!paths) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
for (const [pattern, replacements] of Object.entries(paths)) {
|
|
67
|
+
const wildcardValue = matchTsconfigPathPattern(source, pattern);
|
|
68
|
+
if (wildcardValue === null) {
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
for (const replacement of replacements) {
|
|
72
|
+
const candidate = path.resolve(baseUrl, replacement.replace("*", wildcardValue));
|
|
73
|
+
const existingFile = getExistingFile(candidate);
|
|
74
|
+
if (existingFile) {
|
|
75
|
+
return existingFile;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return null;
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
export const buildOnTheFly = async ({ files, projectDir = process.cwd(), }) => {
|
|
11
84
|
if (storyblokConfig.flushCache) {
|
|
12
85
|
await remove(path.join(`${storyblokConfig.cacheDir}`, `sb-mig`));
|
|
13
86
|
}
|
|
14
|
-
const projectDir = process.cwd();
|
|
15
87
|
const cacheDir = path.join(`${projectDir}`, `${storyblokConfig.cacheDir}`, `sb-mig`);
|
|
16
88
|
const BATCH_SIZE = 5;
|
|
17
89
|
const total = files.length;
|
|
@@ -24,6 +96,11 @@ export const buildOnTheFly = async ({ files }) => {
|
|
|
24
96
|
const inputOptions = {
|
|
25
97
|
input: filePath,
|
|
26
98
|
plugins: [
|
|
99
|
+
createTsconfigPathsResolver(projectDir),
|
|
100
|
+
nodeResolve({
|
|
101
|
+
extensions: RESOLVE_EXTENSIONS,
|
|
102
|
+
preferBuiltins: true,
|
|
103
|
+
}),
|
|
27
104
|
rollupSwc({
|
|
28
105
|
swc: {
|
|
29
106
|
jsc: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sb-mig",
|
|
3
|
-
"version": "6.0.0-beta.
|
|
3
|
+
"version": "6.0.0-beta.6",
|
|
4
4
|
"description": "CLI to rule the world. (and handle stuff related to Storyblok CMS)",
|
|
5
5
|
"author": "Marcin Krawczyk <marckraw@icloud.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -73,6 +73,7 @@
|
|
|
73
73
|
"test:all": "npm run test:unit && npm run test:api-live && npm run test:e2e"
|
|
74
74
|
},
|
|
75
75
|
"dependencies": {
|
|
76
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
76
77
|
"@rollup/plugin-swc": "^0.4.0",
|
|
77
78
|
"@swc/core": "1.3.41",
|
|
78
79
|
"@swc/helpers": "^0.5.18",
|
|
@@ -94,7 +95,6 @@
|
|
|
94
95
|
"devDependencies": {
|
|
95
96
|
"@commitlint/cli": "^17.7.1",
|
|
96
97
|
"@commitlint/config-conventional": "^17.7.0",
|
|
97
|
-
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
98
98
|
"@ryansonshine/commitizen": "^4.2.8",
|
|
99
99
|
"@ryansonshine/cz-conventional-changelog": "^3.3.4",
|
|
100
100
|
"@semantic-release/changelog": "^6.0.3",
|