Skip to content

Commit

Permalink
chore: apply new lint rules
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Jun 14, 2023
1 parent db93afa commit 879a7c3
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 60 deletions.
18 changes: 11 additions & 7 deletions src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,9 @@ declare module 'nitropack' {
"./"
),
join(relative(tsconfigDir, nitro.options.rootDir), "**/*"),
...(nitro.options.srcDir !== nitro.options.rootDir
? [join(relative(tsconfigDir, nitro.options.srcDir), "**/*")]
: []),
...(nitro.options.srcDir === nitro.options.rootDir
? []
: [join(relative(tsconfigDir, nitro.options.srcDir), "**/*")]),
],
};
buildFiles.push({
Expand Down Expand Up @@ -342,27 +342,31 @@ function startRollupWatcher(nitro: Nitro, rollupConfig: RollupConfig) {
watcher.on("event", (event) => {
switch (event.code) {
// The watcher is (re)starting
case "START":
case "START": {
return;
}

// Building an individual bundle
case "BUNDLE_START":
case "BUNDLE_START": {
start = Date.now();
return;
}

// Finished building all bundles
case "END":
case "END": {
nitro.hooks.callHook("compiled", nitro);
nitro.logger.success(
"Nitro built",
start ? `in ${Date.now() - start} ms` : ""
);
nitro.hooks.callHook("dev:reload");
return;
}

// Encountered an error while bundling
case "ERROR":
case "ERROR": {
nitro.logger.error(formatRollupError(event.error));
}
}
});
return watcher;
Expand Down
6 changes: 3 additions & 3 deletions src/cli/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ export default defineCommand({
diff.map((entry) => ` ${entry.toString()}`).join("\n")
);

await (!diff.every((e) => hmrKeyRe.test(e.key))
? reload() // Full reload
: nitro.updateConfig(newConfig.config)); // Hot reload
await (diff.every((e) => hmrKeyRe.test(e.key))
? nitro.updateConfig(newConfig.config) // Full reload
: reload()); // Hot reload
},
},
}
Expand Down
6 changes: 3 additions & 3 deletions src/presets/netlify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ async function writeRedirects(nitro: Nitro) {
)
? "/* /404.html 404"
: "";
let contents = !nitro.options.static
? "/* /.netlify/functions/server 200"
: staticFallback;
let contents = nitro.options.static
? staticFallback
: "/* /.netlify/functions/server 200";

const rules = Object.entries(nitro.options.routeRules).sort(
(a, b) => a[0].split(/\/(?!\*)/).length - b[0].split(/\/(?!\*)/).length
Expand Down
8 changes: 4 additions & 4 deletions src/presets/vercel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,14 +237,14 @@ function generateBuildConfig(nitro: Nitro) {
]
: []),
// If we are using an ISR function as a fallback, then we do not need to output the below fallback route as well
...(!nitro.options.routeRules["/**"]?.isr
? [
...(nitro.options.routeRules["/**"]?.isr
? []
: [
{
src: "/(.*)",
dest: "/__nitro",
},
]
: [])
])
);

return config;
Expand Down
82 changes: 40 additions & 42 deletions src/rollup/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ export const getRollupConfig = (nitro: Nitro): RollupConfig => {
entryFileNames: "index.mjs",
chunkFileNames(chunkInfo) {
let prefix = "";
const lastModule = normalize(
chunkInfo.moduleIds[chunkInfo.moduleIds.length - 1]
);
const lastModule = normalize(chunkInfo.moduleIds.at(-1));
if (lastModule.startsWith(buildServerDir)) {
prefix = join("app", relative(buildServerDir, dirname(lastModule)));
} else if (lastModule.startsWith(runtimeAppDir)) {
Expand Down Expand Up @@ -313,45 +311,7 @@ export const plugins = [
);

// Externals Plugin
if (!nitro.options.noExternals) {
const externalsPlugin = nitro.options.experimental.legacyExternals
? legacyExternals
: externals;
rollupConfig.plugins.push(
externalsPlugin(
defu(nitro.options.externals, {
outDir: nitro.options.output.serverDir,
moduleDirectories: nitro.options.nodeModulesDirs,
external: [...(nitro.options.dev ? [nitro.options.buildDir] : [])],
inline: [
"#",
"~",
"@/",
"~~",
"@@/",
"virtual:",
runtimeDir,
nitro.options.srcDir,
...nitro.options.handlers
.map((m) => m.handler)
.filter((i) => typeof i === "string"),
],
traceOptions: {
base: "/",
processCwd: nitro.options.rootDir,
exportsOnly: true,
},
exportConditions: [
"default",
nitro.options.dev ? "development" : "production",
"module",
"node",
"import",
],
})
)
);
} else {
if (nitro.options.noExternals) {
rollupConfig.plugins.push({
name: "no-externals",
async resolveId(id, from, options) {
Expand Down Expand Up @@ -389,6 +349,44 @@ export const plugins = [
}
},
});
} else {
const externalsPlugin = nitro.options.experimental.legacyExternals
? legacyExternals
: externals;
rollupConfig.plugins.push(
externalsPlugin(
defu(nitro.options.externals, {
outDir: nitro.options.output.serverDir,
moduleDirectories: nitro.options.nodeModulesDirs,
external: [...(nitro.options.dev ? [nitro.options.buildDir] : [])],
inline: [
"#",
"~",
"@/",
"~~",
"@@/",
"virtual:",
runtimeDir,
nitro.options.srcDir,
...nitro.options.handlers
.map((m) => m.handler)
.filter((i) => typeof i === "string"),
],
traceOptions: {
base: "/",
processCwd: nitro.options.rootDir,
exportsOnly: true,
},
exportConditions: [
"default",
nitro.options.dev ? "development" : "production",
"module",
"node",
"import",
],
})
)
);
}

// https://github.com/rollup/plugins/tree/master/packages/node-resolve
Expand Down
2 changes: 1 addition & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ export async function retry(fn: () => Promise<void>, retries: number) {

export function provideFallbackValues(obj: Record<string, any>) {
for (const key in obj) {
if (typeof obj[key] === "undefined" || obj[key] === null) {
if (obj[key] === undefined || obj[key] === null) {
obj[key] = "";
} else if (typeof obj[key] === "object") {
provideFallbackValues(obj[key]);
Expand Down

0 comments on commit 879a7c3

Please sign in to comment.