Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: nonjs-resolve plugin #902

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion examples/12_css/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,16 @@ import { stylexPlugin } from 'vite-plugin-stylex-dev';

/** @type {import('vite').UserConfig} */
export default {
plugins: [vanillaExtractPlugin(), stylexPlugin()],
plugins: [
{
name: 'hack-css-plugin-why-do-we-need-this-FIXME',
resolveId(id: string) {
if (id.endsWith('.css')) {
return id;
}
},
},
vanillaExtractPlugin(),
stylexPlugin(),
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,7 @@ export function deployAwsLambdaPlugin(opts: {
// FIXME This seems too hacky (The use of viteConfig.root, '.', path.resolve and resolveFileName)
const entriesFile = normalizePath(
resolveFileName(
path.resolve(
viteConfig.root || '.',
opts.srcDir,
SRC_ENTRIES + '.jsx',
),
path.resolve(viteConfig.root || '.', opts.srcDir, SRC_ENTRIES),
),
);
const { input } = viteConfig.build?.rollupOptions ?? {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@ export function deployCloudflarePlugin(opts: {
if (source === `${opts.srcDir}/${SERVE_JS}`) {
return source;
}
if (source === 'hono/context-storage') {
return { id: source, external: true };
}
},
load(id) {
if (id === `${opts.srcDir}/${SERVE_JS}`) {
return getServeJsContent(entriesFile);
}
if (id === 'hono/context-storage') {
return '';
}
},
closeBundle() {
const { deploy, unstable_phase } = platformObject.buildOptions || {};
Expand Down
6 changes: 3 additions & 3 deletions packages/waku/src/lib/plugins/vite-plugin-deploy-netlify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ export function deployNetlifyPlugin(opts: {
if (source === `${opts.srcDir}/${SERVE_JS}`) {
return source;
}
if (source === 'hono/context-storage') {
return { id: source, external: true };
}
},
load(id) {
if (id === `${opts.srcDir}/${SERVE_JS}`) {
return getServeJsContent(entriesFile);
}
if (id === 'hono/context-storage') {
return '';
}
},
closeBundle() {
const { deploy, unstable_phase } = platformObject.buildOptions || {};
Expand Down
6 changes: 1 addition & 5 deletions packages/waku/src/lib/plugins/vite-plugin-deploy-partykit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,7 @@ export function deployPartykitPlugin(opts: {
// FIXME This seems too hacky (The use of viteConfig.root, '.', path.resolve and resolveFileName)
const entriesFile = normalizePath(
resolveFileName(
path.resolve(
viteConfig.root || '.',
opts.srcDir,
SRC_ENTRIES + '.jsx',
),
path.resolve(viteConfig.root || '.', opts.srcDir, SRC_ENTRIES),
),
);
const { input } = viteConfig.build?.rollupOptions ?? {};
Expand Down
6 changes: 3 additions & 3 deletions packages/waku/src/lib/plugins/vite-plugin-deploy-vercel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ export function deployVercelPlugin(opts: {
if (source === `${opts.srcDir}/${SERVE_JS}`) {
return source;
}
if (source === 'hono/context-storage') {
return { id: source, external: true };
}
},
load(id) {
if (id === `${opts.srcDir}/${SERVE_JS}`) {
return getServeJsContent(opts.distDir, DIST_PUBLIC, entriesFile);
}
if (id === 'hono/context-storage') {
return '';
}
},
closeBundle() {
const { deploy, unstable_phase } = platformObject.buildOptions || {};
Expand Down
21 changes: 10 additions & 11 deletions packages/waku/src/lib/plugins/vite-plugin-nonjs-resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@ export function nonjsResolvePlugin(): Plugin {
return {
name: 'nonjs-resolve-plugin',
async resolveId(id, importer, options) {
if (!id.endsWith('.js')) {
return id;
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't resolve it because other plugins can't resolve it. We should return undefined.

}
for (const ext of EXTENSIONS) {
const resolved = await this.resolve(
id.slice(0, -extname(id).length) + ext,
importer,
options,
);
if (resolved) {
return resolved;
if (id.endsWith('.js')) {
for (const ext of EXTENSIONS) {
const resolved = await this.resolve(
id.slice(0, -extname(id).length) + ext,
importer,
options,
);
if (resolved) {
return resolved;
}
}
}
},
Expand Down
Loading