@bleedingdev/modern-js-server-utils 3.9.0-ultramodern.9 → 3.9.3-ultramodern.2

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.
@@ -31,6 +31,7 @@ __webpack_require__.d(__webpack_exports__, {
31
31
  FILE_EXTENSIONS: ()=>FILE_EXTENSIONS,
32
32
  compile: ()=>compile
33
33
  });
34
+ const utils_namespaceObject = require("@modern-js/utils");
34
35
  const external_path_namespaceObject = require("path");
35
36
  const FILE_EXTENSIONS = [
36
37
  '.js',
@@ -49,8 +50,18 @@ const compile = async (appDirectory, modernConfig, compileOptions)=>{
49
50
  validateAbsolutePaths(sourceDirs, (dir)=>`source dir ${dir} is not an absolute path.`);
50
51
  validateAbsolutePath(distDir, `dist dir ${distDir} is not an absolute path.`);
51
52
  validateAbsolutePaths(excludeFiles, (file)=>`excluded file ${file} is not an absolute path.`);
52
- const { compileByTs } = await import("../compilers/typescript/index.js");
53
- await compileByTs(appDirectory, modernConfig, compileOptions);
53
+ if (!tsconfigPath) return;
54
+ const { compileServerSources } = await import("../compilers/rslib.js");
55
+ try {
56
+ await compileServerSources(appDirectory, modernConfig, {
57
+ ...compileOptions,
58
+ tsconfigPath
59
+ });
60
+ } catch (error) {
61
+ if (compileOptions.throwErrorInsteadOfExit) throw error;
62
+ utils_namespaceObject.logger.error(error);
63
+ process.exit(1);
64
+ }
54
65
  };
55
66
  exports.FILE_EXTENSIONS = __webpack_exports__.FILE_EXTENSIONS;
56
67
  exports.compile = __webpack_exports__.compile;
@@ -0,0 +1,313 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.n = (module)=>{
5
+ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
6
+ __webpack_require__.d(getter, {
7
+ a: getter
8
+ });
9
+ return getter;
10
+ };
11
+ })();
12
+ (()=>{
13
+ __webpack_require__.d = (exports1, getters, values)=>{
14
+ var define = (defs, kind)=>{
15
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
16
+ enumerable: true,
17
+ [kind]: defs[key]
18
+ });
19
+ };
20
+ define(getters, "get");
21
+ define(values, "value");
22
+ };
23
+ })();
24
+ (()=>{
25
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
26
+ })();
27
+ (()=>{
28
+ __webpack_require__.r = (exports1)=>{
29
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
30
+ value: 'Module'
31
+ });
32
+ Object.defineProperty(exports1, '__esModule', {
33
+ value: true
34
+ });
35
+ };
36
+ })();
37
+ var __webpack_exports__ = {};
38
+ __webpack_require__.r(__webpack_exports__);
39
+ __webpack_require__.d(__webpack_exports__, {
40
+ compileServerSources: ()=>compileServerSources
41
+ });
42
+ const utils_namespaceObject = require("@modern-js/utils");
43
+ const external_path_namespaceObject = require("path");
44
+ var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
45
+ const external_tsgo_js_namespaceObject = require("./tsgo.js");
46
+ const SCRIPT_RE = /\.(?:[cm]?[jt]s|[jt]sx)$/u;
47
+ const DECLARATION_RE = /\.d\.[cm]?ts$/u;
48
+ const TS_RE = /\.[cm]?tsx?$/u;
49
+ const toPosix = (file)=>file.split(external_path_default().sep).join(external_path_default().posix.sep);
50
+ const escapeGlob = (file)=>file.replace(/[()[\]{}*?!+@]/gu, '\\$&');
51
+ const walk = async (dir)=>{
52
+ if (!await utils_namespaceObject.fs.pathExists(dir)) return [];
53
+ const entries = await utils_namespaceObject.fs.readdir(dir, {
54
+ withFileTypes: true
55
+ });
56
+ const files = await Promise.all(entries.map((entry)=>{
57
+ const file = external_path_default().join(dir, entry.name);
58
+ if (entry.isDirectory()) return 'node_modules' === entry.name ? [] : walk(file);
59
+ return [
60
+ file
61
+ ];
62
+ }));
63
+ return files.flat();
64
+ };
65
+ const outputExtension = (file)=>/\.m[jt]s$/u.test(file) ? '.mjs' : /\.c[jt]s$/u.test(file) ? '.cjs' : '.js';
66
+ const collectSources = async (sourceDirs, excludeFiles)=>{
67
+ const excluded = new Set(excludeFiles.map((file)=>external_path_default().normalize(file)));
68
+ return (await Promise.all(sourceDirs.map(walk))).flat().filter((file)=>SCRIPT_RE.test(file) && !DECLARATION_RE.test(file) && !excluded.has(external_path_default().normalize(file)));
69
+ };
70
+ const groupEntries = (appDirectory, files)=>{
71
+ const outputs = new Map();
72
+ const entries = {
73
+ '.js': [],
74
+ '.mjs': [],
75
+ '.cjs': []
76
+ };
77
+ for (const file of files){
78
+ const extension = outputExtension(file);
79
+ const output = `${file.replace(SCRIPT_RE, '')}${extension}`;
80
+ const existing = outputs.get(output);
81
+ if (existing) throw new Error(`"${existing}" and "${file}" both compile to "${toPosix(external_path_default().relative(appDirectory, output))}". Rename one of them.`);
82
+ outputs.set(output, file);
83
+ entries[extension].push(escapeGlob(toPosix(external_path_default().relative(appDirectory, file))));
84
+ }
85
+ return entries;
86
+ };
87
+ const resolveAlias = (appDirectory, alias)=>Object.fromEntries(Object.entries((0, utils_namespaceObject.mergeAlias)(alias)).map(([key, target])=>[
88
+ key,
89
+ [].concat(target).map((value)=>value.startsWith('.') ? external_path_default().resolve(appDirectory, value) : value)
90
+ ]));
91
+ const copyAssets = async (sourceDir, appDirectory, distDir)=>{
92
+ if (!await utils_namespaceObject.fs.pathExists(sourceDir)) return;
93
+ await utils_namespaceObject.fs.copy(sourceDir, external_path_default().join(distDir, external_path_default().relative(appDirectory, sourceDir)), {
94
+ filter: (src)=>!SCRIPT_RE.test(src) && !src.endsWith('tsconfig.json')
95
+ });
96
+ };
97
+ const matchAlias = (alias, request)=>{
98
+ for (const [key, targets] of Object.entries(alias)){
99
+ const exact = key.endsWith('$');
100
+ const name = exact ? key.slice(0, -1) : key;
101
+ if (request === name || !exact && request.startsWith(`${name}/`)) return {
102
+ targets,
103
+ rest: request.slice(name.length)
104
+ };
105
+ }
106
+ };
107
+ const isBareSpecifier = (specifier)=>!/^[./]/u.test(specifier) && !external_path_default().isAbsolute(specifier);
108
+ const relativeSpecifier = (from, to)=>{
109
+ const relative = toPosix(external_path_default().relative(from, to));
110
+ return relative.startsWith('.') ? relative : `./${relative}`;
111
+ };
112
+ const importEmittedFile = ({ appDirectory, distDir, alias, sources, reached, assets })=>async ({ request, context, contextInfo, getResolve })=>{
113
+ if (!request || !context || !contextInfo?.issuer || !getResolve) return;
114
+ const resolve = getResolve();
115
+ const resolved = await resolve(context, request).catch(()=>'');
116
+ if (!resolved) return /^[./]/u.test(request) ? void 0 : request;
117
+ const fromApp = external_path_default().relative(appDirectory, resolved);
118
+ if (fromApp.startsWith('..') || external_path_default().isAbsolute(fromApp) || resolved.includes(`${external_path_default().sep}node_modules${external_path_default().sep}`)) {
119
+ const aliased = matchAlias(alias, request);
120
+ if (!aliased) return request;
121
+ for (const target of aliased.targets.filter(isBareSpecifier)){
122
+ const specifier = `${target}${aliased.rest}`;
123
+ if (await resolve(context, specifier).catch(()=>'') === resolved) return specifier;
124
+ }
125
+ const outputDir = external_path_default().join(distDir, external_path_default().relative(appDirectory, external_path_default().dirname(contextInfo.issuer)));
126
+ return relativeSpecifier(outputDir, resolved);
127
+ }
128
+ const script = SCRIPT_RE.test(resolved) && !DECLARATION_RE.test(resolved);
129
+ if (script && !sources.has(resolved)) reached.add(resolved);
130
+ if (!script) assets.add(resolved);
131
+ const emitted = script ? `${resolved.replace(SCRIPT_RE, '')}${outputExtension(resolved)}` : resolved;
132
+ return relativeSpecifier(external_path_default().dirname(contextInfo.issuer), emitted);
133
+ };
134
+ const compileServerSources = async (appDirectory, config, options)=>{
135
+ const { sourceDirs, distDir, tsconfigPath, moduleType, excludeFiles = [] } = options;
136
+ const sources = new Set(await collectSources(sourceDirs, excludeFiles));
137
+ const copyAllAssets = async ()=>{
138
+ for (const sourceDir of sourceDirs)await copyAssets(sourceDir, appDirectory, distDir);
139
+ };
140
+ const tsgoBinPath = (0, external_tsgo_js_namespaceObject.getTsgoBinPath)(appDirectory);
141
+ const { config: tsconfig, resolvedConfigPath } = await (0, external_tsgo_js_namespaceObject.createResolvedTsgoConfig)(appDirectory, tsconfigPath, sourceDirs, tsgoBinPath, excludeFiles);
142
+ const compilerOptions = tsconfig.compilerOptions ?? {};
143
+ const tsconfigDir = external_path_default().dirname(tsconfigPath);
144
+ const roots = new Set((tsconfig.files ?? []).map((file)=>external_path_default().resolve(tsconfigDir, file)));
145
+ for (const file of sources){
146
+ const checked = true === compilerOptions.allowJs || TS_RE.test(file);
147
+ if (checked && !roots.has(external_path_default().resolve(file))) sources.delete(file);
148
+ }
149
+ const failOnTypeError = false !== compilerOptions.noEmitOnError;
150
+ const declaration = true === compilerOptions.declaration;
151
+ const formats = {
152
+ '.js': 'module' === moduleType ? 'esm' : 'cjs',
153
+ '.mjs': 'esm',
154
+ '.cjs': 'cjs'
155
+ };
156
+ const createLibs = (entries, emitDeclarations)=>{
157
+ const libs = Object.keys(entries).filter((extension)=>entries[extension].length > 0).map((extension)=>({
158
+ format: formats[extension],
159
+ bundle: false,
160
+ autoExtension: false,
161
+ outBase: appDirectory,
162
+ source: {
163
+ entry: {
164
+ index: entries[extension]
165
+ }
166
+ },
167
+ output: {
168
+ filename: {
169
+ js: `[name]${extension}`
170
+ }
171
+ }
172
+ }));
173
+ if (emitDeclarations) {
174
+ libs[0].redirect = {
175
+ dts: {
176
+ extension: 'module' === moduleType
177
+ }
178
+ };
179
+ libs[0].dts = {
180
+ bundle: false,
181
+ distPath: distDir,
182
+ tsgo: true,
183
+ typescriptPath: (0, external_tsgo_js_namespaceObject.getTsgoModulePath)(appDirectory),
184
+ abortOnError: failOnTypeError
185
+ };
186
+ }
187
+ return libs;
188
+ };
189
+ const alias = resolveAlias(appDirectory, config.alias);
190
+ const assets = new Set();
191
+ const build = async ()=>{
192
+ if (0 === sources.size) return;
193
+ const { createRslib } = await import("@rslib/core");
194
+ const appPackage = await utils_namespaceObject.fs.readJSON(external_path_default().join(appDirectory, 'package.json')).catch(()=>void 0);
195
+ const nodeEngine = appPackage?.engines?.node;
196
+ const nodeRange = 'string' == typeof nodeEngine ? utils_namespaceObject.semver.validRange(nodeEngine) : null;
197
+ const nodeVersion = nodeRange ? utils_namespaceObject.semver.minVersion(nodeRange) : null;
198
+ const nodeTarget = nodeVersion?.major ? `node${nodeVersion.major}.${nodeVersion.minor}` : void 0;
199
+ let emitDeclarations = declaration;
200
+ for(;;){
201
+ const reached = new Set();
202
+ const rslib = await createRslib({
203
+ cwd: appDirectory,
204
+ config: {
205
+ lib: createLibs(groupEntries(appDirectory, sources), emitDeclarations),
206
+ source: {
207
+ tsconfigPath: resolvedConfigPath,
208
+ ...compilerOptions.experimentalDecorators ? {
209
+ decorators: {
210
+ version: 'legacy'
211
+ }
212
+ } : {}
213
+ },
214
+ resolve: {
215
+ alias
216
+ },
217
+ output: {
218
+ target: 'node',
219
+ distPath: {
220
+ root: distDir
221
+ },
222
+ cleanDistPath: false,
223
+ sourceMap: {
224
+ js: 'source-map'
225
+ }
226
+ },
227
+ performance: {
228
+ buildCache: false
229
+ },
230
+ tools: {
231
+ rspack: (rspackConfig)=>{
232
+ if (nodeTarget) rspackConfig.target = nodeTarget;
233
+ rspackConfig.externals = [
234
+ importEmittedFile({
235
+ appDirectory,
236
+ distDir,
237
+ alias,
238
+ sources,
239
+ reached,
240
+ assets
241
+ }),
242
+ ...[
243
+ rspackConfig.externals ?? []
244
+ ].flat()
245
+ ];
246
+ }
247
+ }
248
+ }
249
+ });
250
+ await rslib.build();
251
+ emitDeclarations = false;
252
+ if (0 === reached.size) return;
253
+ for (const file of reached)sources.add(file);
254
+ }
255
+ };
256
+ const typeCheck = async ()=>{
257
+ if (0 === roots.size) return;
258
+ const result = await (0, external_tsgo_js_namespaceObject.runTsgo)(tsgoBinPath, [
259
+ '-p',
260
+ resolvedConfigPath,
261
+ '--noEmit'
262
+ ], {
263
+ cwd: appDirectory,
264
+ reject: false
265
+ });
266
+ if (0 === result.code) return;
267
+ const diagnostics = result.stdout.trim() || result.stderr.trim();
268
+ if (!failOnTypeError) return void utils_namespaceObject.logger.warn(`TS-Go type check found errors:\n${diagnostics}`);
269
+ throw new Error([
270
+ `TS-Go type check failed with exit code ${result.code}.`,
271
+ diagnostics
272
+ ].filter(Boolean).join('\n'));
273
+ };
274
+ const checkReachedSources = async ()=>{
275
+ const reachedRoots = [
276
+ ...sources
277
+ ].filter((file)=>!roots.has(external_path_default().resolve(file)) && (true === compilerOptions.allowJs || TS_RE.test(file)));
278
+ if (0 === reachedRoots.length) return typeCheck();
279
+ for (const file of reachedRoots)roots.add(external_path_default().resolve(file));
280
+ tsconfig.files = [
281
+ ...tsconfig.files ?? [],
282
+ ...reachedRoots.map((file)=>toPosix(external_path_default().relative(tsconfigDir, file)))
283
+ ];
284
+ await utils_namespaceObject.fs.writeFile(resolvedConfigPath, JSON.stringify(tsconfig, null, 2));
285
+ return typeCheck();
286
+ };
287
+ let results;
288
+ try {
289
+ const built = await Promise.allSettled([
290
+ build()
291
+ ]);
292
+ results = [
293
+ ...await Promise.allSettled([
294
+ checkReachedSources()
295
+ ]),
296
+ ...built
297
+ ];
298
+ } finally{
299
+ await utils_namespaceObject.fs.remove(resolvedConfigPath);
300
+ }
301
+ const failure = results.find((result)=>'rejected' === result.status);
302
+ if (failure) throw failure.reason;
303
+ await copyAllAssets();
304
+ for (const asset of assets)await utils_namespaceObject.fs.copy(asset, external_path_default().join(distDir, external_path_default().relative(appDirectory, asset)));
305
+ utils_namespaceObject.logger.info('Server sources compiled');
306
+ };
307
+ exports.compileServerSources = __webpack_exports__.compileServerSources;
308
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
309
+ "compileServerSources"
310
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
311
+ Object.defineProperty(exports, '__esModule', {
312
+ value: true
313
+ });
@@ -0,0 +1,181 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.n = (module)=>{
5
+ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
6
+ __webpack_require__.d(getter, {
7
+ a: getter
8
+ });
9
+ return getter;
10
+ };
11
+ })();
12
+ (()=>{
13
+ __webpack_require__.d = (exports1, getters, values)=>{
14
+ var define = (defs, kind)=>{
15
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
16
+ enumerable: true,
17
+ [kind]: defs[key]
18
+ });
19
+ };
20
+ define(getters, "get");
21
+ define(values, "value");
22
+ };
23
+ })();
24
+ (()=>{
25
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
26
+ })();
27
+ (()=>{
28
+ __webpack_require__.r = (exports1)=>{
29
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
30
+ value: 'Module'
31
+ });
32
+ Object.defineProperty(exports1, '__esModule', {
33
+ value: true
34
+ });
35
+ };
36
+ })();
37
+ var __webpack_exports__ = {};
38
+ __webpack_require__.r(__webpack_exports__);
39
+ __webpack_require__.d(__webpack_exports__, {
40
+ createResolvedTsgoConfig: ()=>createResolvedTsgoConfig,
41
+ getTsgoBinPath: ()=>getTsgoBinPath,
42
+ getTsgoModulePath: ()=>getTsgoModulePath,
43
+ runTsgo: ()=>runTsgo
44
+ });
45
+ const utils_namespaceObject = require("@modern-js/utils");
46
+ const external_child_process_namespaceObject = require("child_process");
47
+ const external_path_namespaceObject = require("path");
48
+ var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
49
+ let resolvedConfigCount = 0;
50
+ const createResolvedTsgoConfig = async (appDirectory, tsconfigPath, sourceDirs, tsgoBinPath, excludeFiles = [])=>{
51
+ const tsconfigDir = external_path_default().dirname(tsconfigPath);
52
+ const output = await runTsgo(tsgoBinPath, [
53
+ '--showConfig',
54
+ '-p',
55
+ tsconfigPath
56
+ ], {
57
+ cwd: tsconfigDir
58
+ });
59
+ const config = JSON.parse(output.stdout);
60
+ config.compilerOptions ??= {};
61
+ const options = config.compilerOptions;
62
+ options.rootDir = appDirectory;
63
+ options.composite = false;
64
+ options.declarationMap = false;
65
+ options.incremental = false;
66
+ options.noEmit = true !== options.declaration;
67
+ options.jsx ??= 'react-jsx';
68
+ delete options.emitDeclarationOnly;
69
+ delete options.outDir;
70
+ delete options.tsBuildInfoFile;
71
+ config.files = filterSourceFiles(tsconfigDir, sourceDirs, config.files, excludeFiles);
72
+ delete config.include;
73
+ delete config.references;
74
+ if (void 0 !== options.baseUrl) {
75
+ const baseUrl = external_path_default().resolve(tsconfigDir, options.baseUrl);
76
+ if (options.paths) options.paths = Object.fromEntries(Object.entries(options.paths).map(([key, targets])=>[
77
+ key,
78
+ targets.map((target)=>{
79
+ const relative = external_path_default().relative(tsconfigDir, external_path_default().resolve(baseUrl, target)).split(external_path_default().sep).join(external_path_default().posix.sep);
80
+ return relative.startsWith('.') ? relative : `./${relative}`;
81
+ })
82
+ ]));
83
+ delete options.baseUrl;
84
+ }
85
+ if ([
86
+ 'node',
87
+ 'node10'
88
+ ].includes(String(options.moduleResolution).toLowerCase())) delete options.moduleResolution;
89
+ const resolvedConfigPath = external_path_default().join(tsconfigDir, `.tsgo.${process.pid}.${resolvedConfigCount++}.resolved.json`);
90
+ await utils_namespaceObject.fs.writeFile(resolvedConfigPath, JSON.stringify(config, null, 2));
91
+ return {
92
+ config,
93
+ resolvedConfigPath
94
+ };
95
+ };
96
+ const toPosix = (file)=>file.split(external_path_default().sep).join(external_path_default().posix.sep);
97
+ const filterSourceFiles = (tsconfigDir, sourceDirs, files = [], excludeFiles = [])=>{
98
+ const sourcePosixPaths = sourceDirs.map(toPosix);
99
+ const excludedPaths = new Set(excludeFiles.map((file)=>toPosix(external_path_default().normalize(file))));
100
+ return files.filter((fileName)=>{
101
+ const absoluteFileName = toPosix(external_path_default().resolve(tsconfigDir, fileName));
102
+ if (excludedPaths.has(absoluteFileName)) return false;
103
+ return fileName.endsWith('.d.ts') || sourcePosixPaths.some((sourceDir)=>absoluteFileName.includes(sourceDir));
104
+ });
105
+ };
106
+ const runTsgo = (tsgoBinPath, args, options)=>new Promise((resolve, reject)=>{
107
+ const child = (0, external_child_process_namespaceObject.spawn)(process.execPath, [
108
+ tsgoBinPath,
109
+ ...args
110
+ ], {
111
+ cwd: options.cwd,
112
+ stdio: [
113
+ 'ignore',
114
+ 'pipe',
115
+ 'pipe'
116
+ ]
117
+ });
118
+ let stdout = '';
119
+ let stderr = '';
120
+ child.stdout.on('data', (data)=>{
121
+ stdout += data;
122
+ });
123
+ child.stderr.on('data', (data)=>{
124
+ stderr += data;
125
+ });
126
+ child.on('error', reject);
127
+ child.on('close', (code)=>{
128
+ const result = {
129
+ stdout,
130
+ stderr,
131
+ code: code ?? 1
132
+ };
133
+ if (false !== options.reject && 0 !== result.code) return void reject(new Error(stderr || stdout || `tsgo exited with ${result.code}`));
134
+ resolve(result);
135
+ });
136
+ });
137
+ const resolveTypeScriptPackage = (resolvePaths)=>{
138
+ try {
139
+ return require.resolve("typescript/package.json", {
140
+ paths: resolvePaths
141
+ });
142
+ } catch {
143
+ throw new Error('TypeScript 7.0.2 could not be found! Please install "typescript@7.0.2" in your project to type-check BFF/server code.');
144
+ }
145
+ };
146
+ const getTsgoBinPath = (appDirectory, resolvePaths = [
147
+ appDirectory,
148
+ __dirname
149
+ ])=>{
150
+ const pkgPath = resolveTypeScriptPackage(resolvePaths);
151
+ const pkgDir = external_path_default().dirname(pkgPath);
152
+ const pkg = require(pkgPath);
153
+ if ("typescript" !== pkg.name || '7.0.2' !== pkg.version) throw new Error(`Server compilation requires typescript@7.0.2; found ${pkg.name ?? 'unnamed package'}@${pkg.version ?? 'unknown version'} at ${pkgPath}.`);
154
+ if ('string' != typeof pkg.bin?.tsc || !pkg.bin.tsc) throw new Error(`typescript@7.0.2 declares no tsc executable: ${pkgPath}.`);
155
+ const binPath = external_path_default().resolve(pkgDir, pkg.bin.tsc);
156
+ const relativeBinPath = external_path_default().relative(pkgDir, binPath);
157
+ if (relativeBinPath.startsWith(`..${external_path_default().sep}`) || external_path_default().isAbsolute(relativeBinPath) || !utils_namespaceObject.fs.existsSync(binPath) || !utils_namespaceObject.fs.statSync(binPath).isFile()) throw new Error(`typescript@7.0.2 declared tsc executable is missing or outside its package: ${binPath}.`);
158
+ return binPath;
159
+ };
160
+ const getTsgoModulePath = (appDirectory, resolvePaths = [
161
+ appDirectory,
162
+ __dirname
163
+ ])=>{
164
+ resolveTypeScriptPackage(resolvePaths);
165
+ return require.resolve("typescript", {
166
+ paths: resolvePaths
167
+ });
168
+ };
169
+ exports.createResolvedTsgoConfig = __webpack_exports__.createResolvedTsgoConfig;
170
+ exports.getTsgoBinPath = __webpack_exports__.getTsgoBinPath;
171
+ exports.getTsgoModulePath = __webpack_exports__.getTsgoModulePath;
172
+ exports.runTsgo = __webpack_exports__.runTsgo;
173
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
174
+ "createResolvedTsgoConfig",
175
+ "getTsgoBinPath",
176
+ "getTsgoModulePath",
177
+ "runTsgo"
178
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
179
+ Object.defineProperty(exports, '__esModule', {
180
+ value: true
181
+ });
@@ -1,3 +1,4 @@
1
+ import { logger } from "@modern-js/utils";
1
2
  import * as __rspack_external_path from "path";
2
3
  const FILE_EXTENSIONS = [
3
4
  '.js',
@@ -16,7 +17,17 @@ const compile = async (appDirectory, modernConfig, compileOptions)=>{
16
17
  validateAbsolutePaths(sourceDirs, (dir)=>`source dir ${dir} is not an absolute path.`);
17
18
  validateAbsolutePath(distDir, `dist dir ${distDir} is not an absolute path.`);
18
19
  validateAbsolutePaths(excludeFiles, (file)=>`excluded file ${file} is not an absolute path.`);
19
- const { compileByTs } = await import("../compilers/typescript/index.mjs");
20
- await compileByTs(appDirectory, modernConfig, compileOptions);
20
+ if (!tsconfigPath) return;
21
+ const { compileServerSources } = await import("../compilers/rslib.mjs");
22
+ try {
23
+ await compileServerSources(appDirectory, modernConfig, {
24
+ ...compileOptions,
25
+ tsconfigPath
26
+ });
27
+ } catch (error) {
28
+ if (compileOptions.throwErrorInsteadOfExit) throw error;
29
+ logger.error(error);
30
+ process.exit(1);
31
+ }
21
32
  };
22
33
  export { FILE_EXTENSIONS, compile };