Skip to content

Commit

Permalink
fix: resolve all ESM module if possible (#915)
Browse files Browse the repository at this point in the history
  • Loading branch information
louisgv authored Mar 20, 2024
1 parent 2876857 commit b13e4a8
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 17 deletions.
2 changes: 1 addition & 1 deletion cli/create-plasmo/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-plasmo",
"version": "0.85.0",
"version": "0.85.1",
"description": "Create Plasmo Framework Browser Extension",
"main": "dist/index.js",
"bin": "bin/index.mjs",
Expand Down
2 changes: 1 addition & 1 deletion cli/plasmo/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "plasmo",
"version": "0.85.0",
"version": "0.85.1",
"description": "The Plasmo Framework CLI",
"publishConfig": {
"types": "dist/type.d.ts"
Expand Down
2 changes: 1 addition & 1 deletion core/parcel-config/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@plasmohq/parcel-config",
"version": "0.40.3",
"version": "0.40.4",
"license": "MIT",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion core/parcel-resolver-post/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@plasmohq/parcel-resolver-post",
"version": "0.4.3",
"version": "0.4.4",
"description": "Plasmo Parcel Resolver Post-processing",
"files": [
"dist"
Expand Down
17 changes: 5 additions & 12 deletions core/parcel-resolver-post/src/handle-module-exports.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import type { ResolverProps, ResolverResult } from "./shared"

// TODO: move this stuff into plasmo.config.ts
const knownEsmPackageSet = new Set(["firebase-admin", "svelte", "ai"])

// Last resort resolver for weird packages:
export async function handleModuleExport({
specifier,
Expand All @@ -14,16 +11,12 @@ export async function handleModuleExport({
}

try {
const segments = specifier.split("/")

if (segments.length > 2 || knownEsmPackageSet.has(segments[0])) {
const filePath = require.resolve(specifier, {
paths: [dependency.resolveFrom]
})
const filePath = require.resolve(specifier, {
paths: [dependency.resolveFrom]
})

return {
filePath
}
return {
filePath
}
} catch {}

Expand Down
2 changes: 1 addition & 1 deletion core/parcel-resolver-post/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { handleTsPath } from "./handle-ts-path"
export default new Resolver({
async resolve(props) {
return (
(await handleHacks(props)) ||
(await handleTsPath(props)) ||
(await handleModuleExport(props)) ||
(await handleHacks(props)) ||
null
)
}
Expand Down

0 comments on commit b13e4a8

Please sign in to comment.