Skip to content

Commit

Permalink
remove old esm<>cjs support
Browse files Browse the repository at this point in the history
  • Loading branch information
FredKSchott committed Mar 14, 2021
1 parent e9e227b commit ec4d3d7
Showing 1 changed file with 6 additions and 37 deletions.
43 changes: 6 additions & 37 deletions snowpack/src/sources/local.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import crypto from 'crypto';
import {
InstallOptions,
InstallTarget,
resolveDependencyManifest as _resolveDependencyManifest,
resolveEntrypoint,
} from 'esinstall';
import {InstallOptions, InstallTarget, resolveEntrypoint} from 'esinstall';
import projectCacheDir from 'find-cache-dir';
import findUp from 'find-up';
import {existsSync, promises as fs} from 'fs';
import PQueue from 'p-queue';
import * as colors from 'kleur/colors';
import slash from 'slash';
import mkdirp from 'mkdirp';
import PQueue from 'p-queue';
import path from 'path';
import rimraf from 'rimraf';
import slash from 'slash';
import {getBuiltFileUrls} from '../build/file-urls';
import {logger} from '../logger';
import {scanCodeImportsExports, transformFileImports} from '../rewrite-imports';
Expand All @@ -20,8 +17,8 @@ import {
CommandOptions,
ImportMap,
PackageSource,
SnowpackConfig,
PackageSourceLocal,
SnowpackConfig,
} from '../types';
import {
createInstallTarget,
Expand All @@ -31,8 +28,6 @@ import {
isRemoteUrl,
} from '../util';
import {installPackages} from './local-install';
import findUp from 'find-up';
import mkdirp from 'mkdirp';

const PROJECT_CACHE_DIR =
projectCacheDir({name: 'snowpack'}) ||
Expand All @@ -52,10 +47,6 @@ const NEVER_PEER_PACKAGES: string[] = [
'tslib',
];

function isPackageEsm(packageManifest: any): boolean {
return !!(packageManifest.module || packageManifest.exports || packageManifest.type === 'module');
}

function getRootPackageDirectory(loc: string) {
const parts = loc.split('node_modules');
if (parts.length === 1) {
Expand Down Expand Up @@ -341,17 +332,6 @@ export default {
...Object.keys(packageManifest.peerDependencies || {}),
].filter((ext) => ext !== _packageName && !NEVER_PEER_PACKAGES.includes(ext));

function getMemoizedResolveDependencyManifest() {
const results = {};
return (packageName: string) => {
results[packageName] =
results[packageName] ||
_resolveDependencyManifest(packageName, rootPackageDirectory!);
return results[packageName];
};
}
const resolveDependencyManifest = getMemoizedResolveDependencyManifest();

const installOptions: InstallOptions = {
dest: installDest,
cwd: packageManifestLoc,
Expand All @@ -360,17 +340,6 @@ export default {
sourcemap: config.buildOptions.sourcemap,
alias: config.alias,
external: externalPackages,
// ESM<>CJS Compatability: If we can detect that a dependency is common.js vs. ESM, then
// we can provide this hint to esinstall to improve our cross-package import support.
externalEsm: (imp) => {
const specParts = imp.split('/');
let _packageName: string = specParts.shift()!;
if (_packageName?.startsWith('@')) {
_packageName += '/' + specParts.shift();
}
const [, result] = resolveDependencyManifest(_packageName);
return !result || isPackageEsm(result);
},
};
if (config.packageOptions.source === 'local') {
if (config.packageOptions.polyfillNode !== undefined) {
Expand Down

0 comments on commit ec4d3d7

Please sign in to comment.