Skip to content

Commit

Permalink
Revert "feat: use esm.sh tree shaking params (#407)" (#414)
Browse files Browse the repository at this point in the history
This reverts commit 0f0e2c2.
  • Loading branch information
andy-haynes authored Apr 15, 2024
1 parent 060714c commit 3dd666f
Showing 1 changed file with 7 additions and 35 deletions.
42 changes: 7 additions & 35 deletions packages/compiler/src/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,38 +262,21 @@ const aggregateModuleImports = (imports: ImportExpression[]): ImportsByType => {
* Build the importmap URL based on package name/URL
* @param moduleName module name specified in the import statement
* @param modulePath module import path
* @param references set of destructured references for tree shaking
*/
const buildModulePackageUrl = ({
moduleName,
modulePath,
references,
}: {
moduleName: string;
modulePath: string;
references: string[];
}) => {
export const buildModulePackageUrl = (
moduleName: string,
modulePath: string
) => {
if (modulePath.startsWith('https://')) {
return {
moduleName,
url: modulePath,
};
}

const queryStringParams = new Map([
['alias', 'react:preact/compat'],
['external', 'preact'],
]);

if (references.length) {
queryStringParams.set('exports', references.join(','));
}

return {
moduleName,
url: `https://esm.sh/${moduleName}?${[...queryStringParams.entries()]
.map((entry) => entry.join('='))
.join('&')}`,
url: `https://esm.sh/${moduleName}?alias=react:preact/compat&external=preact`,
};
};

Expand All @@ -305,19 +288,8 @@ export const buildContainerModuleImports = (
containerModuleImports: ModuleImport[]
) => {
const importedModules = containerModuleImports.reduce(
(importMap, { moduleName, modulePath, imports }) => {
const destructuredReferences = imports
.filter(({ isDestructured }) => isDestructured)
.map(({ reference }) => reference!);

const importMapEntries = buildModulePackageUrl({
moduleName,
modulePath,
references:
destructuredReferences.length === imports.length
? destructuredReferences
: [],
});
(importMap, { moduleName, modulePath }) => {
const importMapEntries = buildModulePackageUrl(moduleName, modulePath);

if (!importMapEntries) {
return importMap;
Expand Down

0 comments on commit 3dd666f

Please sign in to comment.