@simplysm/sd-cli 12.5.17 → 12.5.18
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/build-tools/SdCliIndexFileGenerator.js +2 -2
- package/dist/build-tools/SdCliIndexFileGenerator.js.map +1 -1
- package/dist/build-tools/SdLinter.js +5 -2
- package/dist/build-tools/SdLinter.js.map +1 -1
- package/dist/build-tools/SdReactBundler.d.ts +24 -0
- package/dist/build-tools/SdReactBundler.js +294 -0
- package/dist/build-tools/SdReactBundler.js.map +1 -0
- package/dist/build-tools/SdReactBundlerContext.d.ts +14 -0
- package/dist/build-tools/SdReactBundlerContext.js +59 -0
- package/dist/build-tools/SdReactBundlerContext.js.map +1 -0
- package/dist/build-tools/SdTsCompiler.js +274 -226
- package/dist/build-tools/SdTsCompiler.js.map +1 -1
- package/dist/builders/SdCliClientBuilder.js +41 -17
- package/dist/builders/SdCliClientBuilder.js.map +1 -1
- package/dist/bundle-plugins/sdReactPlugin.d.ts +15 -0
- package/dist/bundle-plugins/sdReactPlugin.js +116 -0
- package/dist/bundle-plugins/sdReactPlugin.js.map +1 -0
- package/dist/entry/SdCliProject.js +2 -2
- package/dist/entry/SdCliProject.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/package.json +11 -11
- package/src/build-tools/SdCliIndexFileGenerator.ts +2 -2
- package/src/build-tools/SdLinter.ts +8 -2
- package/src/build-tools/SdReactBundler.ts +370 -0
- package/src/build-tools/SdReactBundlerContext.ts +71 -0
- package/src/build-tools/SdTsCompiler.ts +227 -112
- package/src/builders/SdCliClientBuilder.ts +52 -27
- package/src/bundle-plugins/sdReactPlugin.ts +160 -0
- package/src/entry/SdCliProject.ts +6 -2
- package/src/index.ts +3 -0
- package/tsconfig.json +5 -11
- package/eslint.config.js +0 -1
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import esbuild from "esbuild";
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { ISdTsCompilerResult, SdTsCompiler } from "../build-tools/SdTsCompiler";
|
|
5
|
+
import { convertTypeScriptDiagnostic } from "@angular/build/src/tools/esbuild/angular/diagnostics";
|
|
6
|
+
import postcss from "postcss";
|
|
7
|
+
import { FsUtil } from "@simplysm/sd-core-node";
|
|
8
|
+
import postcssUrl from "postcss-url";
|
|
9
|
+
import postcssHas from "css-has-pseudo";
|
|
10
|
+
import autoprefixer from "autoprefixer";
|
|
11
|
+
|
|
12
|
+
export function sdReactPlugin(conf: {
|
|
13
|
+
pkgPath: string;
|
|
14
|
+
dev: boolean;
|
|
15
|
+
modifiedFileSet: Set<string>;
|
|
16
|
+
result: IReactPluginResultCache;
|
|
17
|
+
}): esbuild.Plugin {
|
|
18
|
+
return {
|
|
19
|
+
name: "sd-ng-compiler",
|
|
20
|
+
setup: (build: esbuild.PluginBuild) => {
|
|
21
|
+
const compiler = new SdTsCompiler({
|
|
22
|
+
pkgPath: conf.pkgPath,
|
|
23
|
+
additionalOptions: { declaration: false },
|
|
24
|
+
isDevMode: conf.dev,
|
|
25
|
+
isForBundle: true,
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
let buildResult: ISdTsCompilerResult;
|
|
29
|
+
const outputContentsCacheMap = new Map<string, string | Uint8Array | undefined>();
|
|
30
|
+
|
|
31
|
+
//---------------------------
|
|
32
|
+
|
|
33
|
+
build.onStart(async () => {
|
|
34
|
+
compiler.invalidate(conf.modifiedFileSet);
|
|
35
|
+
for (const modifiedFile of conf.modifiedFileSet) {
|
|
36
|
+
outputContentsCacheMap.delete(modifiedFile);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
buildResult = await compiler.buildAsync();
|
|
40
|
+
|
|
41
|
+
conf.result.watchFileSet = buildResult.watchFileSet;
|
|
42
|
+
conf.result.affectedFileSet = buildResult.affectedFileSet;
|
|
43
|
+
conf.result.program = buildResult.program;
|
|
44
|
+
|
|
45
|
+
//-- return err/warn
|
|
46
|
+
return {
|
|
47
|
+
errors: [
|
|
48
|
+
...buildResult.typescriptDiagnostics
|
|
49
|
+
.filter((item) => item.category === ts.DiagnosticCategory.Error)
|
|
50
|
+
.map((item) => convertTypeScriptDiagnostic(ts, item)),
|
|
51
|
+
...Array.from(buildResult.stylesheetBundlingResultMap.values()).flatMap((item) => item.errors),
|
|
52
|
+
].filterExists(),
|
|
53
|
+
warnings: [
|
|
54
|
+
...buildResult.typescriptDiagnostics
|
|
55
|
+
.filter((item) => item.category !== ts.DiagnosticCategory.Error)
|
|
56
|
+
.map((item) => convertTypeScriptDiagnostic(ts, item)),
|
|
57
|
+
// ...Array.from(buildResult.stylesheetResultMap.values()).flatMap(item => item.warnings)
|
|
58
|
+
],
|
|
59
|
+
};
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
build.onLoad({ filter: /\.tsx?$/ }, (args) => {
|
|
63
|
+
const output = outputContentsCacheMap.get(path.normalize(args.path));
|
|
64
|
+
if (output != null) {
|
|
65
|
+
return { contents: output, loader: "js" };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const emittedJsFile = buildResult.emittedFilesCacheMap.get(path.normalize(args.path))?.last();
|
|
69
|
+
if (!emittedJsFile) {
|
|
70
|
+
throw new Error(`ts 빌더 결과 emit 파일이 존재하지 않습니다. ${args.path}`);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const contents = emittedJsFile.text;
|
|
74
|
+
|
|
75
|
+
outputContentsCacheMap.set(path.normalize(args.path), contents);
|
|
76
|
+
|
|
77
|
+
return { contents, loader: "js" };
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
build.onLoad({ filter: /\.[cm]?jsx?$/ }, (args) => {
|
|
81
|
+
conf.result.watchFileSet!.add(path.normalize(args.path));
|
|
82
|
+
return null;
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
build.onLoad({ filter: /\.css$/ }, async (args) => {
|
|
86
|
+
conf.result.watchFileSet!.add(path.normalize(args.path));
|
|
87
|
+
const output = outputContentsCacheMap.get(path.normalize(args.path));
|
|
88
|
+
if (output != null) {
|
|
89
|
+
return {
|
|
90
|
+
contents: output,
|
|
91
|
+
loader: "file",
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const css = await FsUtil.readFileAsync(path.normalize(args.path));
|
|
96
|
+
const result = await postcss()
|
|
97
|
+
.use(
|
|
98
|
+
autoprefixer({
|
|
99
|
+
overrideBrowserslist: ["Chrome > 78"],
|
|
100
|
+
}),
|
|
101
|
+
)
|
|
102
|
+
.use(
|
|
103
|
+
postcssUrl({
|
|
104
|
+
url: "copy",
|
|
105
|
+
}),
|
|
106
|
+
)
|
|
107
|
+
.use(postcssHas())
|
|
108
|
+
.process(css, {
|
|
109
|
+
from: path.normalize(args.path),
|
|
110
|
+
to: path.resolve(conf.pkgPath, "dist", "media", path.basename(args.path)),
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
outputContentsCacheMap.set(path.normalize(args.path), result.css);
|
|
114
|
+
|
|
115
|
+
return { contents: result.css, loader: "file" };
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
build.onLoad(
|
|
119
|
+
{
|
|
120
|
+
filter: new RegExp(
|
|
121
|
+
"(" +
|
|
122
|
+
Object.keys(build.initialOptions.loader!)
|
|
123
|
+
.map((item) => "\\" + item)
|
|
124
|
+
.join("|") +
|
|
125
|
+
")$",
|
|
126
|
+
),
|
|
127
|
+
},
|
|
128
|
+
(args) => {
|
|
129
|
+
conf.result.watchFileSet!.add(path.normalize(args.path));
|
|
130
|
+
return null;
|
|
131
|
+
},
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
build.onEnd((result) => {
|
|
135
|
+
for (const { outputFiles, metafile } of buildResult.stylesheetBundlingResultMap.values()) {
|
|
136
|
+
result.outputFiles = result.outputFiles ?? [];
|
|
137
|
+
result.outputFiles.push(...outputFiles);
|
|
138
|
+
|
|
139
|
+
if (result.metafile && metafile) {
|
|
140
|
+
result.metafile.inputs = { ...result.metafile.inputs, ...metafile.inputs };
|
|
141
|
+
result.metafile.outputs = { ...result.metafile.outputs, ...metafile.outputs };
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
conf.result.outputFiles = result.outputFiles;
|
|
146
|
+
conf.result.metafile = result.metafile;
|
|
147
|
+
|
|
148
|
+
conf.modifiedFileSet.clear();
|
|
149
|
+
});
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export interface IReactPluginResultCache {
|
|
155
|
+
watchFileSet?: Set<string>;
|
|
156
|
+
affectedFileSet?: Set<string>;
|
|
157
|
+
program?: ts.Program;
|
|
158
|
+
outputFiles?: esbuild.OutputFile[];
|
|
159
|
+
metafile?: esbuild.Metafile;
|
|
160
|
+
}
|
|
@@ -47,7 +47,9 @@ export class SdCliProject {
|
|
|
47
47
|
if (!projNpmConf.workspaces) {
|
|
48
48
|
throw new Error("프로젝트 package.json에 workspaces가 설정되어있지 않습니다.");
|
|
49
49
|
}
|
|
50
|
-
const allPkgPaths =
|
|
50
|
+
const allPkgPaths = (
|
|
51
|
+
await projNpmConf.workspaces.mapManyAsync(async (item) => await FsUtil.globAsync(item))
|
|
52
|
+
).filter((item) => !item.includes("."));
|
|
51
53
|
let pkgPaths = allPkgPaths.filter((pkgPath) => path.basename(pkgPath) in projConf.packages);
|
|
52
54
|
if (opt.pkgNames.length !== 0) {
|
|
53
55
|
pkgPaths = pkgPaths.filter((pkgPath) => opt.pkgNames.includes(path.basename(pkgPath)));
|
|
@@ -330,7 +332,9 @@ export class SdCliProject {
|
|
|
330
332
|
if (!projNpmConf.workspaces) {
|
|
331
333
|
throw new Error("프로젝트 package.json에 workspaces가 설정되어있지 않습니다.");
|
|
332
334
|
}
|
|
333
|
-
const allPkgPaths =
|
|
335
|
+
const allPkgPaths = (
|
|
336
|
+
await projNpmConf.workspaces.mapManyAsync(async (item) => await FsUtil.globAsync(item))
|
|
337
|
+
).filter((item) => !item.includes("."));
|
|
334
338
|
let pkgPaths = allPkgPaths.filter((pkgPath) => path.basename(pkgPath) in projConf.packages);
|
|
335
339
|
if (opt.pkgNames.length !== 0) {
|
|
336
340
|
pkgPaths = pkgPaths.filter((pkgPath) => opt.pkgNames.includes(path.basename(pkgPath)));
|
package/src/index.ts
CHANGED
|
@@ -4,6 +4,8 @@ export * from "./build-tools/SdCliNgRoutesFileGenerator";
|
|
|
4
4
|
export * from "./build-tools/SdLinter";
|
|
5
5
|
export * from "./build-tools/SdNgBundler";
|
|
6
6
|
export * from "./build-tools/SdNgBundlerContext";
|
|
7
|
+
export * from "./build-tools/SdReactBundler";
|
|
8
|
+
export * from "./build-tools/SdReactBundlerContext";
|
|
7
9
|
export * from "./build-tools/SdServerBundler";
|
|
8
10
|
export * from "./build-tools/SdTsCompiler";
|
|
9
11
|
export * from "./build-tools/SdTsLibBundler";
|
|
@@ -13,6 +15,7 @@ export * from "./builders/SdCliServerBuilder";
|
|
|
13
15
|
export * from "./builders/SdCliTsLibBuilder";
|
|
14
16
|
export * from "./bundle-plugins/KeysTransformer";
|
|
15
17
|
export * from "./bundle-plugins/sdNgPlugin";
|
|
18
|
+
export * from "./bundle-plugins/sdReactPlugin";
|
|
16
19
|
export * from "./bundle-plugins/sdServerPlugin";
|
|
17
20
|
export * from "./commons";
|
|
18
21
|
export * from "./entry/SdCliElectron";
|
package/tsconfig.json
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
{
|
|
2
|
-
"extends": "
|
|
2
|
+
"extends": "../tsconfig.json",
|
|
3
3
|
"compilerOptions": {
|
|
4
|
-
"lib": [
|
|
5
|
-
|
|
6
|
-
]
|
|
7
|
-
"outDir": "./dist"
|
|
4
|
+
"lib": ["ES2021"],
|
|
5
|
+
"outDir": "./dist",
|
|
6
|
+
"types": ["node", "eslint", "yargs"]
|
|
8
7
|
},
|
|
9
|
-
"files": [
|
|
10
|
-
"src/index.ts",
|
|
11
|
-
"src/sd-cli.ts",
|
|
12
|
-
"src/build-cluster.ts",
|
|
13
|
-
"src/server-worker.ts"
|
|
14
|
-
]
|
|
8
|
+
"files": ["./src/index.ts", "./src/sd-cli.ts", "./src/build-cluster.ts", "./src/server-worker.ts"]
|
|
15
9
|
}
|
package/eslint.config.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from "../eslint-plugin/src/configs/typescript.js";
|