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

chore: remove duplicate import specifier check #2317

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 0 additions & 9 deletions snowpack/src/build/import-resolver.ts
Expand Up @@ -6,7 +6,6 @@ import {
findMatchingAliasEntry,
getExtensionMatch,
hasExtension,
isRemoteUrl,
replaceExtension,
} from '../util';
import {getUrlForFile} from './file-urls';
Expand Down Expand Up @@ -69,14 +68,6 @@ function resolveSourceSpecifier(lazyFileLoc: string, config: SnowpackConfig) {
*/
export function createImportResolver({fileLoc, config}: {fileLoc: string; config: SnowpackConfig}) {
return function importResolver(spec: string): string | false {
// Ignore "http://*" imports
if (isRemoteUrl(spec)) {
return spec;
}
// Ignore packages marked as external
if (config.packageOptions.external?.includes(spec)) {
return spec;
}
if (spec.startsWith('/')) {
return spec;
}
Expand Down
18 changes: 10 additions & 8 deletions snowpack/src/commands/build.ts
Expand Up @@ -268,6 +268,15 @@ class FileBuilder {
config: this.config,
});
const resolvedCode = await transformFileImports(file, (spec) => {
// Ignore "http://*" imports
if (isRemoteUrl(spec)) {
return spec;
}
// Ignore packages marked as external
if (this.config.packageOptions.external?.includes(spec)) {
return spec;
}

// Try to resolve the specifier to a known URL in the project
let resolvedImportUrl = resolveImportSpecifier(spec);
// If not resolved, then this is a package. During build, dependencies are always
Expand All @@ -282,14 +291,7 @@ class FileBuilder {
logger.error(`${file.locOnDisk} - Could not resolve unknown import "${spec}".`);
return spec;
}
// Ignore "http://*" imports
if (isRemoteUrl(resolvedImportUrl)) {
return resolvedImportUrl;
}
// Ignore packages marked as external
if (this.config.packageOptions.external?.includes(resolvedImportUrl)) {
return resolvedImportUrl;
}

// Handle normal "./" & "../" import specifiers
const importExtName = path.extname(resolvedImportUrl);
const isBundling = !!this.config.optimize?.bundle;
Expand Down
18 changes: 10 additions & 8 deletions snowpack/src/commands/dev.ts
Expand Up @@ -715,6 +715,15 @@ export async function startServer(commandOptions: CommandOptions): Promise<Snowp
baseExt: responseExt,
},
(spec) => {
// Ignore "http://*" imports
if (isRemoteUrl(spec)) {
return spec;
}
// Ignore packages marked as external
if (config.packageOptions.external?.includes(spec)) {
return spec;
}

// Try to resolve the specifier to a known URL in the project
let resolvedImportUrl = resolveImportSpecifier(spec);
// Handle a package import
Expand All @@ -726,14 +735,7 @@ export async function startServer(commandOptions: CommandOptions): Promise<Snowp
missingPackages.push(spec);
return spec;
}
// Ignore "http://*" imports
if (isRemoteUrl(resolvedImportUrl)) {
return resolvedImportUrl;
}
// Ignore packages marked as external
if (config.packageOptions.external?.includes(resolvedImportUrl)) {
return spec;
}

// Handle normal "./" & "../" import specifiers
const importExtName = path.posix.extname(resolvedImportUrl);
const isProxyImport = importExtName && importExtName !== '.js';
Expand Down