nitro-nightly 3.0.1-20260106-202835-5325b208 → 3.0.1-20260106-205209-b085a480
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/common.mjs +24899 -0
- package/dist/_build/rolldown.mjs +6 -9
- package/dist/_build/rollup.mjs +6 -8
- package/dist/_build/vite.build.mjs +1 -1
- package/dist/{_dev.mjs → _chunks/dev.mjs} +4 -7
- package/dist/{_nitro.mjs → _chunks/nitro.mjs} +16 -195
- package/dist/_chunks/nitro2.mjs +101 -0
- package/dist/_chunks/utils.mjs +278 -0
- package/dist/_libs/@hiogawa/vite-plugin-fullstack.mjs +32 -4
- package/dist/_libs/@jridgewell/gen-mapping.mjs +304 -2
- package/dist/_libs/@jridgewell/remapping.mjs +1 -2
- package/dist/_libs/@rollup/plugin-commonjs.mjs +75 -31
- package/dist/_libs/@rollup/plugin-inject.mjs +1 -3
- package/dist/_libs/@rollup/plugin-json.mjs +1 -1
- package/dist/_libs/@rollup/plugin-node-resolve.mjs +1111 -7
- package/dist/_libs/c12.mjs +597 -41
- package/dist/_libs/chokidar.mjs +235 -2
- package/dist/_libs/confbox.mjs +454 -1476
- package/dist/_libs/estree-walker.mjs +1 -144
- package/dist/_libs/giget.mjs +2235 -1377
- package/dist/_libs/httpxy.mjs +1 -1
- package/dist/_libs/unimport.mjs +1547 -1772
- package/dist/_presets.mjs +3 -9
- package/dist/builder.mjs +7 -12
- package/dist/cli/_chunks/{build2.mjs → build.mjs} +1 -1
- package/dist/cli/_chunks/dev.mjs +3 -5
- package/dist/cli/_chunks/list.mjs +1 -1
- package/dist/cli/_chunks/prepare.mjs +1 -1
- package/dist/cli/_chunks/run.mjs +1 -1
- package/dist/cli/index.mjs +1 -1
- package/dist/vite.mjs +14 -1128
- package/package.json +1 -1
- package/dist/_build/rollup2.mjs +0 -56
- package/dist/_build/shared.mjs +0 -60
- package/dist/_build/shared2.mjs +0 -40
- package/dist/_build/shared3.mjs +0 -68
- package/dist/_libs/@jridgewell/resolve-uri.mjs +0 -166
- package/dist/_libs/@jridgewell/sourcemap-codec.mjs +0 -167
- package/dist/_libs/@jridgewell/trace-mapping.mjs +0 -141
- package/dist/_libs/@rolldown/pluginutils.mjs +0 -31
- package/dist/_libs/@rollup/plugin-replace.mjs +0 -104
- package/dist/_libs/@rollup/pluginutils.mjs +0 -241
- package/dist/_libs/acorn.mjs +0 -5034
- package/dist/_libs/commondir.mjs +0 -22
- package/dist/_libs/deepmerge.mjs +0 -86
- package/dist/_libs/dot-prop.mjs +0 -138
- package/dist/_libs/dotenv.mjs +0 -345
- package/dist/_libs/duplexer.mjs +0 -71
- package/dist/_libs/etag.mjs +0 -80
- package/dist/_libs/exsolve.mjs +0 -1007
- package/dist/_libs/fdir.mjs +0 -514
- package/dist/_libs/function-bind.mjs +0 -63
- package/dist/_libs/gzip-size.mjs +0 -21
- package/dist/_libs/hasown.mjs +0 -14
- package/dist/_libs/is-core-module.mjs +0 -220
- package/dist/_libs/is-module.mjs +0 -13
- package/dist/_libs/is-reference.mjs +0 -33
- package/dist/_libs/js-tokens.mjs +0 -382
- package/dist/_libs/knitwork.mjs +0 -124
- package/dist/_libs/local-pkg.mjs +0 -125
- package/dist/_libs/magic-string.mjs +0 -939
- package/dist/_libs/mime.mjs +0 -1391
- package/dist/_libs/mlly.mjs +0 -1415
- package/dist/_libs/node-fetch-native.mjs +0 -7
- package/dist/_libs/nypm.mjs +0 -239
- package/dist/_libs/path-parse.mjs +0 -47
- package/dist/_libs/pathe.mjs +0 -202
- package/dist/_libs/perfect-debounce.mjs +0 -89
- package/dist/_libs/picomatch.mjs +0 -1673
- package/dist/_libs/pkg-types.mjs +0 -197
- package/dist/_libs/pretty-bytes.mjs +0 -116
- package/dist/_libs/quansync.mjs +0 -90
- package/dist/_libs/rc9.mjs +0 -136
- package/dist/_libs/readdirp.mjs +0 -237
- package/dist/_libs/resolve.mjs +0 -689
- package/dist/_libs/std-env.mjs +0 -158
- package/dist/_libs/strip-literal.mjs +0 -51
- package/dist/_libs/tinyexec.mjs +0 -627
- package/dist/_libs/tinyglobby.mjs +0 -292
- package/dist/_libs/unplugin-utils.mjs +0 -61
- package/dist/_libs/unplugin.mjs +0 -1225
- package/dist/_libs/untyped.mjs +0 -271
- package/dist/_libs/unwasm.mjs +0 -5895
- package/dist/_libs/webpack-virtual-modules.mjs +0 -272
- package/dist/_nitro2.mjs +0 -303
- /package/dist/{_rolldown.mjs → _common.mjs} +0 -0
|
@@ -1,272 +0,0 @@
|
|
|
1
|
-
import { r as __require, t as __commonJSMin } from "../_rolldown.mjs";
|
|
2
|
-
|
|
3
|
-
//#region node_modules/.pnpm/webpack-virtual-modules@0.6.2/node_modules/webpack-virtual-modules/lib/virtual-stats.js
|
|
4
|
-
var require_virtual_stats = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
5
|
-
var __importDefault = exports && exports.__importDefault || function(mod) {
|
|
6
|
-
return mod && mod.__esModule ? mod : { "default": mod };
|
|
7
|
-
};
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.VirtualStats = void 0;
|
|
10
|
-
const constants_1 = __importDefault(__require("constants"));
|
|
11
|
-
var VirtualStats = class {
|
|
12
|
-
constructor(config) {
|
|
13
|
-
for (const key in config) {
|
|
14
|
-
if (!Object.prototype.hasOwnProperty.call(config, key)) continue;
|
|
15
|
-
this[key] = config[key];
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
_checkModeProperty(property) {
|
|
19
|
-
return (this.mode & constants_1.default.S_IFMT) === property;
|
|
20
|
-
}
|
|
21
|
-
isDirectory() {
|
|
22
|
-
return this._checkModeProperty(constants_1.default.S_IFDIR);
|
|
23
|
-
}
|
|
24
|
-
isFile() {
|
|
25
|
-
return this._checkModeProperty(constants_1.default.S_IFREG);
|
|
26
|
-
}
|
|
27
|
-
isBlockDevice() {
|
|
28
|
-
return this._checkModeProperty(constants_1.default.S_IFBLK);
|
|
29
|
-
}
|
|
30
|
-
isCharacterDevice() {
|
|
31
|
-
return this._checkModeProperty(constants_1.default.S_IFCHR);
|
|
32
|
-
}
|
|
33
|
-
isSymbolicLink() {
|
|
34
|
-
return this._checkModeProperty(constants_1.default.S_IFLNK);
|
|
35
|
-
}
|
|
36
|
-
isFIFO() {
|
|
37
|
-
return this._checkModeProperty(constants_1.default.S_IFIFO);
|
|
38
|
-
}
|
|
39
|
-
isSocket() {
|
|
40
|
-
return this._checkModeProperty(constants_1.default.S_IFSOCK);
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
exports.VirtualStats = VirtualStats;
|
|
44
|
-
}));
|
|
45
|
-
|
|
46
|
-
//#endregion
|
|
47
|
-
//#region node_modules/.pnpm/webpack-virtual-modules@0.6.2/node_modules/webpack-virtual-modules/lib/index.js
|
|
48
|
-
var require_lib = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
49
|
-
const path_1 = (exports && exports.__importDefault || function(mod) {
|
|
50
|
-
return mod && mod.__esModule ? mod : { "default": mod };
|
|
51
|
-
})(__require("path"));
|
|
52
|
-
const virtual_stats_1 = require_virtual_stats();
|
|
53
|
-
let inode = 45e6;
|
|
54
|
-
const ALL = "all";
|
|
55
|
-
const STATIC = "static";
|
|
56
|
-
const DYNAMIC = "dynamic";
|
|
57
|
-
function checkActivation(instance) {
|
|
58
|
-
if (!instance._compiler) throw new Error("You must use this plugin only after creating webpack instance!");
|
|
59
|
-
}
|
|
60
|
-
function getModulePath(filePath, compiler) {
|
|
61
|
-
return path_1.default.isAbsolute(filePath) ? filePath : path_1.default.join(compiler.context, filePath);
|
|
62
|
-
}
|
|
63
|
-
function createWebpackData(result) {
|
|
64
|
-
return (backendOrStorage) => {
|
|
65
|
-
if (backendOrStorage._data) {
|
|
66
|
-
const curLevelIdx = backendOrStorage._currentLevel;
|
|
67
|
-
return {
|
|
68
|
-
result,
|
|
69
|
-
level: backendOrStorage._levels[curLevelIdx]
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
return [null, result];
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
function getData(storage, key) {
|
|
76
|
-
if (storage._data instanceof Map) return storage._data.get(key);
|
|
77
|
-
else if (storage._data) return storage.data[key];
|
|
78
|
-
else if (storage.data instanceof Map) return storage.data.get(key);
|
|
79
|
-
else return storage.data[key];
|
|
80
|
-
}
|
|
81
|
-
function setData(backendOrStorage, key, valueFactory) {
|
|
82
|
-
const value = valueFactory(backendOrStorage);
|
|
83
|
-
if (backendOrStorage._data instanceof Map) backendOrStorage._data.set(key, value);
|
|
84
|
-
else if (backendOrStorage._data) backendOrStorage.data[key] = value;
|
|
85
|
-
else if (backendOrStorage.data instanceof Map) backendOrStorage.data.set(key, value);
|
|
86
|
-
else backendOrStorage.data[key] = value;
|
|
87
|
-
}
|
|
88
|
-
function getStatStorage(fileSystem) {
|
|
89
|
-
if (fileSystem._statStorage) return fileSystem._statStorage;
|
|
90
|
-
else if (fileSystem._statBackend) return fileSystem._statBackend;
|
|
91
|
-
else throw new Error("Couldn't find a stat storage");
|
|
92
|
-
}
|
|
93
|
-
function getFileStorage(fileSystem) {
|
|
94
|
-
if (fileSystem._readFileStorage) return fileSystem._readFileStorage;
|
|
95
|
-
else if (fileSystem._readFileBackend) return fileSystem._readFileBackend;
|
|
96
|
-
else throw new Error("Couldn't find a readFileStorage");
|
|
97
|
-
}
|
|
98
|
-
function getReadDirBackend(fileSystem) {
|
|
99
|
-
if (fileSystem._readdirBackend) return fileSystem._readdirBackend;
|
|
100
|
-
else if (fileSystem._readdirStorage) return fileSystem._readdirStorage;
|
|
101
|
-
else throw new Error("Couldn't find a readDirStorage from Webpack Internals");
|
|
102
|
-
}
|
|
103
|
-
function getRealpathBackend(fileSystem) {
|
|
104
|
-
if (fileSystem._realpathBackend) return fileSystem._realpathBackend;
|
|
105
|
-
}
|
|
106
|
-
var VirtualModulesPlugin = class {
|
|
107
|
-
constructor(modules) {
|
|
108
|
-
this._compiler = null;
|
|
109
|
-
this._watcher = null;
|
|
110
|
-
this._staticModules = modules || null;
|
|
111
|
-
}
|
|
112
|
-
getModuleList(filter = ALL) {
|
|
113
|
-
var _a, _b;
|
|
114
|
-
let modules = {};
|
|
115
|
-
const shouldGetStaticModules = filter === ALL || filter === STATIC;
|
|
116
|
-
const shouldGetDynamicModules = filter === ALL || filter === DYNAMIC;
|
|
117
|
-
if (shouldGetStaticModules) modules = Object.assign(Object.assign({}, modules), this._staticModules);
|
|
118
|
-
if (shouldGetDynamicModules) {
|
|
119
|
-
const finalInputFileSystem = (_a = this._compiler) === null || _a === void 0 ? void 0 : _a.inputFileSystem;
|
|
120
|
-
const virtualFiles = (_b = finalInputFileSystem === null || finalInputFileSystem === void 0 ? void 0 : finalInputFileSystem._virtualFiles) !== null && _b !== void 0 ? _b : {};
|
|
121
|
-
const dynamicModules = {};
|
|
122
|
-
Object.keys(virtualFiles).forEach((key) => {
|
|
123
|
-
dynamicModules[key] = virtualFiles[key].contents;
|
|
124
|
-
});
|
|
125
|
-
modules = Object.assign(Object.assign({}, modules), dynamicModules);
|
|
126
|
-
}
|
|
127
|
-
return modules;
|
|
128
|
-
}
|
|
129
|
-
writeModule(filePath, contents) {
|
|
130
|
-
if (!this._compiler) throw new Error(`Plugin has not been initialized`);
|
|
131
|
-
checkActivation(this);
|
|
132
|
-
const len = contents ? contents.length : 0;
|
|
133
|
-
const time = Date.now();
|
|
134
|
-
const date = new Date(time);
|
|
135
|
-
const stats = new virtual_stats_1.VirtualStats({
|
|
136
|
-
dev: 8675309,
|
|
137
|
-
nlink: 0,
|
|
138
|
-
uid: 1e3,
|
|
139
|
-
gid: 1e3,
|
|
140
|
-
rdev: 0,
|
|
141
|
-
blksize: 4096,
|
|
142
|
-
ino: inode++,
|
|
143
|
-
mode: 33188,
|
|
144
|
-
size: len,
|
|
145
|
-
blocks: Math.floor(len / 4096),
|
|
146
|
-
atime: date,
|
|
147
|
-
mtime: date,
|
|
148
|
-
ctime: date,
|
|
149
|
-
birthtime: date
|
|
150
|
-
});
|
|
151
|
-
const modulePath = getModulePath(filePath, this._compiler);
|
|
152
|
-
if (process.env.WVM_DEBUG) console.log(this._compiler.name, "Write virtual module:", modulePath, contents);
|
|
153
|
-
let finalWatchFileSystem = this._watcher && this._watcher.watchFileSystem;
|
|
154
|
-
while (finalWatchFileSystem && finalWatchFileSystem.wfs) finalWatchFileSystem = finalWatchFileSystem.wfs;
|
|
155
|
-
let finalInputFileSystem = this._compiler.inputFileSystem;
|
|
156
|
-
while (finalInputFileSystem && finalInputFileSystem._inputFileSystem) finalInputFileSystem = finalInputFileSystem._inputFileSystem;
|
|
157
|
-
finalInputFileSystem._writeVirtualFile(modulePath, stats, contents);
|
|
158
|
-
if (finalWatchFileSystem && finalWatchFileSystem.watcher && (finalWatchFileSystem.watcher.fileWatchers.size || finalWatchFileSystem.watcher.fileWatchers.length)) {
|
|
159
|
-
const fileWatchers = finalWatchFileSystem.watcher.fileWatchers instanceof Map ? Array.from(finalWatchFileSystem.watcher.fileWatchers.values()) : finalWatchFileSystem.watcher.fileWatchers;
|
|
160
|
-
for (let fileWatcher of fileWatchers) {
|
|
161
|
-
if ("watcher" in fileWatcher) fileWatcher = fileWatcher.watcher;
|
|
162
|
-
if (fileWatcher.path === modulePath) {
|
|
163
|
-
if (process.env.DEBUG) console.log(this._compiler.name, "Emit file change:", modulePath, time);
|
|
164
|
-
delete fileWatcher.directoryWatcher._cachedTimeInfoEntries;
|
|
165
|
-
fileWatcher.emit("change", time, null);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
apply(compiler) {
|
|
171
|
-
this._compiler = compiler;
|
|
172
|
-
const afterEnvironmentHook = () => {
|
|
173
|
-
let finalInputFileSystem = compiler.inputFileSystem;
|
|
174
|
-
while (finalInputFileSystem && finalInputFileSystem._inputFileSystem) finalInputFileSystem = finalInputFileSystem._inputFileSystem;
|
|
175
|
-
if (!finalInputFileSystem._writeVirtualFile) {
|
|
176
|
-
const originalPurge = finalInputFileSystem.purge;
|
|
177
|
-
finalInputFileSystem.purge = () => {
|
|
178
|
-
originalPurge.apply(finalInputFileSystem, []);
|
|
179
|
-
if (finalInputFileSystem._virtualFiles) Object.keys(finalInputFileSystem._virtualFiles).forEach((file) => {
|
|
180
|
-
const data = finalInputFileSystem._virtualFiles[file];
|
|
181
|
-
finalInputFileSystem._writeVirtualFile(file, data.stats, data.contents);
|
|
182
|
-
});
|
|
183
|
-
};
|
|
184
|
-
finalInputFileSystem._writeVirtualFile = (file, stats, contents) => {
|
|
185
|
-
const statStorage = getStatStorage(finalInputFileSystem);
|
|
186
|
-
const fileStorage = getFileStorage(finalInputFileSystem);
|
|
187
|
-
const readDirStorage = getReadDirBackend(finalInputFileSystem);
|
|
188
|
-
const realPathStorage = getRealpathBackend(finalInputFileSystem);
|
|
189
|
-
finalInputFileSystem._virtualFiles = finalInputFileSystem._virtualFiles || {};
|
|
190
|
-
finalInputFileSystem._virtualFiles[file] = {
|
|
191
|
-
stats,
|
|
192
|
-
contents
|
|
193
|
-
};
|
|
194
|
-
setData(statStorage, file, createWebpackData(stats));
|
|
195
|
-
setData(fileStorage, file, createWebpackData(contents));
|
|
196
|
-
const segments = file.split(/[\\/]/);
|
|
197
|
-
let count = segments.length - 1;
|
|
198
|
-
const minCount = segments[0] ? 1 : 0;
|
|
199
|
-
while (count > minCount) {
|
|
200
|
-
const dir = segments.slice(0, count).join(path_1.default.sep) || path_1.default.sep;
|
|
201
|
-
try {
|
|
202
|
-
finalInputFileSystem.readdirSync(dir);
|
|
203
|
-
} catch (e) {
|
|
204
|
-
const time = Date.now();
|
|
205
|
-
const dirStats = new virtual_stats_1.VirtualStats({
|
|
206
|
-
dev: 8675309,
|
|
207
|
-
nlink: 0,
|
|
208
|
-
uid: 1e3,
|
|
209
|
-
gid: 1e3,
|
|
210
|
-
rdev: 0,
|
|
211
|
-
blksize: 4096,
|
|
212
|
-
ino: inode++,
|
|
213
|
-
mode: 16877,
|
|
214
|
-
size: stats.size,
|
|
215
|
-
blocks: Math.floor(stats.size / 4096),
|
|
216
|
-
atime: time,
|
|
217
|
-
mtime: time,
|
|
218
|
-
ctime: time,
|
|
219
|
-
birthtime: time
|
|
220
|
-
});
|
|
221
|
-
setData(readDirStorage, dir, createWebpackData([]));
|
|
222
|
-
if (realPathStorage) setData(realPathStorage, dir, createWebpackData(dir));
|
|
223
|
-
setData(statStorage, dir, createWebpackData(dirStats));
|
|
224
|
-
}
|
|
225
|
-
let dirData = getData(getReadDirBackend(finalInputFileSystem), dir);
|
|
226
|
-
dirData = dirData[1] || dirData.result;
|
|
227
|
-
const filename = segments[count];
|
|
228
|
-
if (dirData.indexOf(filename) < 0) {
|
|
229
|
-
const files = dirData.concat([filename]).sort();
|
|
230
|
-
setData(getReadDirBackend(finalInputFileSystem), dir, createWebpackData(files));
|
|
231
|
-
} else break;
|
|
232
|
-
count--;
|
|
233
|
-
}
|
|
234
|
-
};
|
|
235
|
-
}
|
|
236
|
-
};
|
|
237
|
-
const afterResolversHook = () => {
|
|
238
|
-
if (this._staticModules) {
|
|
239
|
-
for (const [filePath, contents] of Object.entries(this._staticModules)) this.writeModule(filePath, contents);
|
|
240
|
-
this._staticModules = null;
|
|
241
|
-
}
|
|
242
|
-
};
|
|
243
|
-
const version = typeof compiler.webpack === "undefined" ? 4 : 5;
|
|
244
|
-
const watchRunHook = (watcher, callback) => {
|
|
245
|
-
this._watcher = watcher.compiler || watcher;
|
|
246
|
-
const virtualFiles = compiler.inputFileSystem._virtualFiles;
|
|
247
|
-
const fts = compiler.fileTimestamps;
|
|
248
|
-
if (virtualFiles && fts && typeof fts.set === "function") Object.keys(virtualFiles).forEach((file) => {
|
|
249
|
-
const mtime = +virtualFiles[file].stats.mtime;
|
|
250
|
-
fts.set(file, version === 4 ? mtime : {
|
|
251
|
-
safeTime: mtime,
|
|
252
|
-
timestamp: mtime
|
|
253
|
-
});
|
|
254
|
-
});
|
|
255
|
-
callback();
|
|
256
|
-
};
|
|
257
|
-
if (compiler.hooks) {
|
|
258
|
-
compiler.hooks.afterEnvironment.tap("VirtualModulesPlugin", afterEnvironmentHook);
|
|
259
|
-
compiler.hooks.afterResolvers.tap("VirtualModulesPlugin", afterResolversHook);
|
|
260
|
-
compiler.hooks.watchRun.tapAsync("VirtualModulesPlugin", watchRunHook);
|
|
261
|
-
} else {
|
|
262
|
-
compiler.plugin("after-environment", afterEnvironmentHook);
|
|
263
|
-
compiler.plugin("after-resolvers", afterResolversHook);
|
|
264
|
-
compiler.plugin("watch-run", watchRunHook);
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
};
|
|
268
|
-
module.exports = VirtualModulesPlugin;
|
|
269
|
-
}));
|
|
270
|
-
|
|
271
|
-
//#endregion
|
|
272
|
-
export { require_lib as t };
|
package/dist/_nitro2.mjs
DELETED
|
@@ -1,303 +0,0 @@
|
|
|
1
|
-
import { a as isAbsolute, l as relative, o as join, r as dirname, t as resolveAlias, u as resolve } from "./_libs/pathe.mjs";
|
|
2
|
-
import { t as resolveModulePath } from "./_libs/exsolve.mjs";
|
|
3
|
-
import { i as writeFile, r as resolveNitroPath, t as isDirectory } from "./_build/shared2.mjs";
|
|
4
|
-
import { t as glob } from "./_libs/tinyglobby.mjs";
|
|
5
|
-
import { a as lookupNodeModuleSubpath, o as parseNodeModulePath } from "./_libs/mlly.mjs";
|
|
6
|
-
import { n as resolveSchema, t as generateTypes } from "./_libs/untyped.mjs";
|
|
7
|
-
import { M as toExports } from "./_libs/unimport.mjs";
|
|
8
|
-
import { existsSync, promises } from "node:fs";
|
|
9
|
-
import { defu } from "defu";
|
|
10
|
-
import { withBase, withLeadingSlash, withoutTrailingSlash } from "ufo";
|
|
11
|
-
import { runtimeDir } from "nitro/meta";
|
|
12
|
-
|
|
13
|
-
//#region src/scan.ts
|
|
14
|
-
const GLOB_SCAN_PATTERN = "**/*.{js,mjs,cjs,ts,mts,cts,tsx,jsx}";
|
|
15
|
-
const suffixRegex = /(\.(?<method>connect|delete|get|head|options|patch|post|put|trace))?(\.(?<env>dev|prod|prerender))?$/;
|
|
16
|
-
async function scanAndSyncOptions(nitro) {
|
|
17
|
-
const scannedPlugins = await scanPlugins(nitro);
|
|
18
|
-
for (const plugin of scannedPlugins) if (!nitro.options.plugins.includes(plugin)) nitro.options.plugins.push(plugin);
|
|
19
|
-
if (nitro.options.experimental.tasks) {
|
|
20
|
-
const scannedTasks = await scanTasks(nitro);
|
|
21
|
-
for (const scannedTask of scannedTasks) if (scannedTask.name in nitro.options.tasks) {
|
|
22
|
-
if (!nitro.options.tasks[scannedTask.name].handler) nitro.options.tasks[scannedTask.name].handler = scannedTask.handler;
|
|
23
|
-
} else nitro.options.tasks[scannedTask.name] = {
|
|
24
|
-
handler: scannedTask.handler,
|
|
25
|
-
description: ""
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
const scannedModules = await scanModules(nitro);
|
|
29
|
-
nitro.options.modules = nitro.options.modules || [];
|
|
30
|
-
for (const modPath of scannedModules) if (!nitro.options.modules.includes(modPath)) nitro.options.modules.push(modPath);
|
|
31
|
-
}
|
|
32
|
-
async function scanHandlers(nitro) {
|
|
33
|
-
const middleware = await scanMiddleware(nitro);
|
|
34
|
-
const handlers = await Promise.all([scanServerRoutes(nitro, nitro.options.apiDir || "api", nitro.options.apiBaseURL || "/api"), scanServerRoutes(nitro, nitro.options.routesDir || "routes")]).then((r) => r.flat());
|
|
35
|
-
nitro.scannedHandlers = [...middleware, ...handlers.filter((h, index, array) => {
|
|
36
|
-
return array.findIndex((h2) => h.route === h2.route && h.method === h2.method && h.env === h2.env) === index;
|
|
37
|
-
})];
|
|
38
|
-
return handlers;
|
|
39
|
-
}
|
|
40
|
-
async function scanMiddleware(nitro) {
|
|
41
|
-
return (await scanFiles(nitro, "middleware")).map((file) => {
|
|
42
|
-
return {
|
|
43
|
-
route: "/**",
|
|
44
|
-
middleware: true,
|
|
45
|
-
handler: file.fullPath
|
|
46
|
-
};
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
async function scanServerRoutes(nitro, dir, prefix = "/") {
|
|
50
|
-
return (await scanFiles(nitro, dir)).map((file) => {
|
|
51
|
-
let route = file.path.replace(/\.[A-Za-z]+$/, "").replace(/\(([^(/\\]+)\)[/\\]/g, "").replace(/\[\.{3}]/g, "**").replace(/\[\.{3}(\w+)]/g, "**:$1").replace(/\[([^/\]]+)]/g, ":$1");
|
|
52
|
-
route = withLeadingSlash(withoutTrailingSlash(withBase(route, prefix)));
|
|
53
|
-
const suffixMatch = route.match(suffixRegex);
|
|
54
|
-
let method;
|
|
55
|
-
let env;
|
|
56
|
-
if (suffixMatch?.index && suffixMatch?.index >= 0) {
|
|
57
|
-
route = route.slice(0, suffixMatch.index);
|
|
58
|
-
method = suffixMatch.groups?.method;
|
|
59
|
-
env = suffixMatch.groups?.env;
|
|
60
|
-
}
|
|
61
|
-
route = route.replace(/\/index$/, "") || "/";
|
|
62
|
-
return {
|
|
63
|
-
handler: file.fullPath,
|
|
64
|
-
lazy: true,
|
|
65
|
-
middleware: false,
|
|
66
|
-
route,
|
|
67
|
-
method,
|
|
68
|
-
env
|
|
69
|
-
};
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
async function scanPlugins(nitro) {
|
|
73
|
-
return (await scanFiles(nitro, "plugins")).map((f) => f.fullPath);
|
|
74
|
-
}
|
|
75
|
-
async function scanTasks(nitro) {
|
|
76
|
-
return (await scanFiles(nitro, "tasks")).map((f) => {
|
|
77
|
-
return {
|
|
78
|
-
name: f.path.replace(/\/index$/, "").replace(/\.[A-Za-z]+$/, "").replace(/\//g, ":"),
|
|
79
|
-
handler: f.fullPath
|
|
80
|
-
};
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
async function scanModules(nitro) {
|
|
84
|
-
return (await scanFiles(nitro, "modules")).map((f) => f.fullPath);
|
|
85
|
-
}
|
|
86
|
-
async function scanFiles(nitro, name) {
|
|
87
|
-
return await Promise.all(nitro.options.scanDirs.map((dir) => scanDir(nitro, dir, name))).then((r) => r.flat());
|
|
88
|
-
}
|
|
89
|
-
async function scanDir(nitro, dir, name) {
|
|
90
|
-
return (await glob(join(name, GLOB_SCAN_PATTERN), {
|
|
91
|
-
cwd: dir,
|
|
92
|
-
dot: true,
|
|
93
|
-
ignore: nitro.options.ignore,
|
|
94
|
-
absolute: true
|
|
95
|
-
}).catch((error) => {
|
|
96
|
-
if (error?.code === "ENOTDIR") {
|
|
97
|
-
nitro.logger.warn(`Ignoring \`${join(dir, name)}\`. It must be a directory.`);
|
|
98
|
-
return [];
|
|
99
|
-
}
|
|
100
|
-
throw error;
|
|
101
|
-
})).map((fullPath) => {
|
|
102
|
-
return {
|
|
103
|
-
fullPath,
|
|
104
|
-
path: relative(join(dir, name), fullPath)
|
|
105
|
-
};
|
|
106
|
-
}).sort((a, b) => a.path.localeCompare(b.path));
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
//#endregion
|
|
110
|
-
//#region src/build/types.ts
|
|
111
|
-
async function writeTypes(nitro) {
|
|
112
|
-
const types = { routes: {} };
|
|
113
|
-
const generatedTypesDir = resolve(nitro.options.rootDir, nitro.options.typescript.generatedTypesDir || "node_modules/.nitro/types");
|
|
114
|
-
const middleware = [...nitro.scannedHandlers, ...nitro.options.handlers];
|
|
115
|
-
for (const mw of middleware) {
|
|
116
|
-
if (typeof mw.handler !== "string" || !mw.route) continue;
|
|
117
|
-
const relativePath = relative(generatedTypesDir, resolveNitroPath(mw.handler, nitro.options)).replace(/\.(js|mjs|cjs|ts|mts|cts|tsx|jsx)$/, "");
|
|
118
|
-
const method = mw.method || "default";
|
|
119
|
-
types.routes[mw.route] ??= {};
|
|
120
|
-
types.routes[mw.route][method] ??= [];
|
|
121
|
-
types.routes[mw.route][method].push(`Simplify<Serialize<Awaited<ReturnType<typeof import('${relativePath}').default>>>>`);
|
|
122
|
-
}
|
|
123
|
-
let autoImportedTypes = [];
|
|
124
|
-
let autoImportExports = "";
|
|
125
|
-
if (nitro.unimport) {
|
|
126
|
-
await nitro.unimport.init();
|
|
127
|
-
const allImports = await nitro.unimport.getImports();
|
|
128
|
-
autoImportExports = toExports(allImports).replace(/#internal\/nitro/g, relative(generatedTypesDir, runtimeDir));
|
|
129
|
-
const resolvedImportPathMap = /* @__PURE__ */ new Map();
|
|
130
|
-
for (const i of allImports) {
|
|
131
|
-
const from = i.typeFrom || i.from;
|
|
132
|
-
if (resolvedImportPathMap.has(from)) continue;
|
|
133
|
-
let path = resolveAlias(from, nitro.options.alias);
|
|
134
|
-
if (!isAbsolute(path)) {
|
|
135
|
-
const resolvedPath = resolveModulePath(from, {
|
|
136
|
-
try: true,
|
|
137
|
-
from: nitro.options.rootDir,
|
|
138
|
-
conditions: [
|
|
139
|
-
"type",
|
|
140
|
-
"node",
|
|
141
|
-
"import"
|
|
142
|
-
],
|
|
143
|
-
suffixes: ["", "/index"],
|
|
144
|
-
extensions: [
|
|
145
|
-
".mjs",
|
|
146
|
-
".cjs",
|
|
147
|
-
".js",
|
|
148
|
-
".mts",
|
|
149
|
-
".cts",
|
|
150
|
-
".ts"
|
|
151
|
-
]
|
|
152
|
-
});
|
|
153
|
-
if (resolvedPath) {
|
|
154
|
-
const { dir, name } = parseNodeModulePath(resolvedPath);
|
|
155
|
-
if (!dir || !name) path = resolvedPath;
|
|
156
|
-
else path = join(dir, name, await lookupNodeModuleSubpath(resolvedPath) || "");
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
if (existsSync(path) && !await isDirectory(path)) path = path.replace(/\.[a-z]+$/, "");
|
|
160
|
-
if (isAbsolute(path)) path = relative(generatedTypesDir, path);
|
|
161
|
-
resolvedImportPathMap.set(from, path);
|
|
162
|
-
}
|
|
163
|
-
autoImportedTypes = [nitro.options.imports && nitro.options.imports.autoImport !== false ? (await nitro.unimport.generateTypeDeclarations({
|
|
164
|
-
exportHelper: false,
|
|
165
|
-
resolvePath: (i) => {
|
|
166
|
-
const from = i.typeFrom || i.from;
|
|
167
|
-
return resolvedImportPathMap.get(from) ?? from;
|
|
168
|
-
}
|
|
169
|
-
})).trim() : ""];
|
|
170
|
-
}
|
|
171
|
-
const generateRoutes = () => [
|
|
172
|
-
"// Generated by nitro",
|
|
173
|
-
"import type { Serialize, Simplify } from \"nitro/types\";",
|
|
174
|
-
"declare module \"nitro/types\" {",
|
|
175
|
-
" type Awaited<T> = T extends PromiseLike<infer U> ? Awaited<U> : T",
|
|
176
|
-
" interface InternalApi {",
|
|
177
|
-
...Object.entries(types.routes).map(([path, methods]) => [
|
|
178
|
-
` '${path}': {`,
|
|
179
|
-
...Object.entries(methods).map(([method, types$1]) => ` '${method}': ${types$1.join(" | ")}`),
|
|
180
|
-
" }"
|
|
181
|
-
].join("\n")),
|
|
182
|
-
" }",
|
|
183
|
-
"}",
|
|
184
|
-
"export {}"
|
|
185
|
-
];
|
|
186
|
-
const config = [
|
|
187
|
-
"// Generated by nitro",
|
|
188
|
-
`declare module "nitro/types" {`,
|
|
189
|
-
nitro.options.typescript.generateRuntimeConfigTypes ? generateTypes(await resolveSchema(Object.fromEntries(Object.entries(nitro.options.runtimeConfig).filter(([key]) => !["app", "nitro"].includes(key)))), {
|
|
190
|
-
interfaceName: "NitroRuntimeConfig",
|
|
191
|
-
addExport: false,
|
|
192
|
-
addDefaults: false,
|
|
193
|
-
allowExtraKeys: false,
|
|
194
|
-
indentation: 2
|
|
195
|
-
}) : "",
|
|
196
|
-
`}`,
|
|
197
|
-
"export {}"
|
|
198
|
-
];
|
|
199
|
-
const declarations = [
|
|
200
|
-
"/// <reference path=\"./nitro-routes.d.ts\" />",
|
|
201
|
-
"/// <reference path=\"./nitro-config.d.ts\" />",
|
|
202
|
-
"/// <reference path=\"./nitro-imports.d.ts\" />"
|
|
203
|
-
];
|
|
204
|
-
const buildFiles = [];
|
|
205
|
-
buildFiles.push({
|
|
206
|
-
path: join(generatedTypesDir, "nitro-routes.d.ts"),
|
|
207
|
-
contents: () => generateRoutes().join("\n")
|
|
208
|
-
});
|
|
209
|
-
buildFiles.push({
|
|
210
|
-
path: join(generatedTypesDir, "nitro-config.d.ts"),
|
|
211
|
-
contents: config.join("\n")
|
|
212
|
-
});
|
|
213
|
-
buildFiles.push({
|
|
214
|
-
path: join(generatedTypesDir, "nitro-imports.d.ts"),
|
|
215
|
-
contents: [...autoImportedTypes, autoImportExports || "export {}"].join("\n")
|
|
216
|
-
});
|
|
217
|
-
buildFiles.push({
|
|
218
|
-
path: join(generatedTypesDir, "nitro.d.ts"),
|
|
219
|
-
contents: declarations.join("\n")
|
|
220
|
-
});
|
|
221
|
-
if (nitro.options.typescript.generateTsConfig) {
|
|
222
|
-
const tsConfigPath = resolve(generatedTypesDir, nitro.options.typescript.tsconfigPath || "tsconfig.json");
|
|
223
|
-
const tsconfigDir = dirname(tsConfigPath);
|
|
224
|
-
const tsConfig = defu(nitro.options.typescript.tsConfig, {
|
|
225
|
-
compilerOptions: {
|
|
226
|
-
esModuleInterop: true,
|
|
227
|
-
allowSyntheticDefaultImports: true,
|
|
228
|
-
skipLibCheck: true,
|
|
229
|
-
target: "ESNext",
|
|
230
|
-
allowJs: true,
|
|
231
|
-
resolveJsonModule: true,
|
|
232
|
-
moduleDetection: "force",
|
|
233
|
-
isolatedModules: true,
|
|
234
|
-
verbatimModuleSyntax: true,
|
|
235
|
-
allowImportingTsExtensions: true,
|
|
236
|
-
strict: nitro.options.typescript.strict,
|
|
237
|
-
noUncheckedIndexedAccess: true,
|
|
238
|
-
noImplicitOverride: true,
|
|
239
|
-
forceConsistentCasingInFileNames: true,
|
|
240
|
-
module: "Preserve",
|
|
241
|
-
jsx: "preserve",
|
|
242
|
-
jsxFactory: "h",
|
|
243
|
-
jsxFragmentFactory: "Fragment",
|
|
244
|
-
paths: { "#imports": [relativeWithDot(tsconfigDir, join(generatedTypesDir, "nitro-imports"))] }
|
|
245
|
-
},
|
|
246
|
-
include: [
|
|
247
|
-
relativeWithDot(tsconfigDir, join(generatedTypesDir, "nitro.d.ts")).replace(/^(?=[^.])/, "./"),
|
|
248
|
-
join(relativeWithDot(tsconfigDir, nitro.options.rootDir), "**/*"),
|
|
249
|
-
...!nitro.options.serverDir || nitro.options.serverDir === nitro.options.rootDir ? [] : [join(relativeWithDot(tsconfigDir, nitro.options.serverDir), "**/*")]
|
|
250
|
-
]
|
|
251
|
-
});
|
|
252
|
-
for (const alias in tsConfig.compilerOptions.paths) {
|
|
253
|
-
const paths = await Promise.all(tsConfig.compilerOptions.paths[alias].map(async (path) => {
|
|
254
|
-
if (!isAbsolute(path)) return path;
|
|
255
|
-
return relativeWithDot(tsconfigDir, (await promises.stat(path).catch(() => null))?.isFile() ? path.replace(/(?<=\w)\.\w+$/g, "") : path);
|
|
256
|
-
}));
|
|
257
|
-
tsConfig.compilerOptions.paths[alias] = [...new Set(paths)];
|
|
258
|
-
}
|
|
259
|
-
tsConfig.include = [...new Set(tsConfig.include.map((p) => isAbsolute(p) ? relativeWithDot(tsconfigDir, p) : p))];
|
|
260
|
-
if (tsConfig.exclude) tsConfig.exclude = [...new Set(tsConfig.exclude.map((p) => isAbsolute(p) ? relativeWithDot(tsconfigDir, p) : p))];
|
|
261
|
-
types.tsConfig = tsConfig;
|
|
262
|
-
buildFiles.push({
|
|
263
|
-
path: tsConfigPath,
|
|
264
|
-
contents: () => JSON.stringify(tsConfig, null, 2)
|
|
265
|
-
});
|
|
266
|
-
}
|
|
267
|
-
await nitro.hooks.callHook("types:extend", types);
|
|
268
|
-
await Promise.all(buildFiles.map(async (file) => {
|
|
269
|
-
await writeFile(resolve(generatedTypesDir, file.path), typeof file.contents === "string" ? file.contents : file.contents());
|
|
270
|
-
}));
|
|
271
|
-
}
|
|
272
|
-
const RELATIVE_RE = /^\.{1,2}\//;
|
|
273
|
-
function relativeWithDot(from, to) {
|
|
274
|
-
const rel = relative(from, to);
|
|
275
|
-
return RELATIVE_RE.test(rel) ? rel : "./" + rel;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
//#endregion
|
|
279
|
-
//#region src/utils/parallel.ts
|
|
280
|
-
async function runParallel(inputs, cb, opts) {
|
|
281
|
-
const tasks = /* @__PURE__ */ new Set();
|
|
282
|
-
function queueNext() {
|
|
283
|
-
const route = inputs.values().next().value;
|
|
284
|
-
if (!route) return;
|
|
285
|
-
inputs.delete(route);
|
|
286
|
-
const task = (opts.interval ? new Promise((resolve$1) => setTimeout(resolve$1, opts.interval)) : Promise.resolve()).then(() => cb(route)).catch((error) => {
|
|
287
|
-
console.error(error);
|
|
288
|
-
});
|
|
289
|
-
tasks.add(task);
|
|
290
|
-
return task.then(() => {
|
|
291
|
-
tasks.delete(task);
|
|
292
|
-
if (inputs.size > 0) return refillQueue();
|
|
293
|
-
});
|
|
294
|
-
}
|
|
295
|
-
function refillQueue() {
|
|
296
|
-
const workers = Math.min(opts.concurrency - tasks.size, inputs.size);
|
|
297
|
-
return Promise.all(Array.from({ length: workers }, () => queueNext()));
|
|
298
|
-
}
|
|
299
|
-
await refillQueue();
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
//#endregion
|
|
303
|
-
export { scanHandlers as i, writeTypes as n, scanAndSyncOptions as r, runParallel as t };
|
|
File without changes
|