Skip to content

Commit

Permalink
fix: svelte 4 module resolution (#650)
Browse files Browse the repository at this point in the history
* fix: get svelte4 working

* fix: svelte 4 module resolution
  • Loading branch information
louisgv authored Jun 29, 2023
1 parent 2a2a4a6 commit 1872f63
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 23 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.77.4",
"version": "0.77.5",
"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.77.4",
"version": "0.77.5",
"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.38.2",
"version": "0.38.3",
"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.3.1",
"version": "0.4.0",
"description": "Plasmo Parcel Resolver Post-processing",
"files": [
"dist"
Expand Down
34 changes: 34 additions & 0 deletions core/parcel-resolver-post/src/handle-hacks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// These are hack resolvers to get over some module resolution issues, with a PR to fix them upstream.

import { dirname, join } from "path"

import type { ResolverProps, ResolverResult } from "./shared"

// Last resort resolver for weird packages:
export async function handleHacks({
specifier,
dependency
}: ResolverProps): Promise<ResolverResult> {
switch (specifier) {
case "svelte/internal/disclose-version": {
// https://github.com/sveltejs/svelte/pull/8874
const sveltePjPath = require.resolve("svelte/package.json", {
paths: [dependency.resolveFrom]
})

return {
filePath: join(
dirname(sveltePjPath),
"src",
"runtime",
"internal",
"disclose-version",
"index.js"
)
}
}

default:
return null
}
}
2 changes: 1 addition & 1 deletion core/parcel-resolver-post/src/handle-module-exports.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ResolverProps, ResolverResult } from "./shared"

const knownEsmPackageSet = new Set(["firebase-admin"])
const knownEsmPackageSet = new Set(["firebase-admin", "svelte"])

// Last resort resolver for weird packages:
export async function handleModuleExport({
Expand Down
6 changes: 5 additions & 1 deletion core/parcel-resolver-post/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { Resolver } from "@parcel/plugin"

import { handleHacks } from "./handle-hacks"
import { handleModuleExport } from "./handle-module-exports"
import { handleTsPath } from "./handle-ts-path"

export default new Resolver({
async resolve(props) {
return (
(await handleTsPath(props)) || (await handleModuleExport(props)) || null
(await handleTsPath(props)) ||
(await handleModuleExport(props)) ||
(await handleHacks(props)) ||
null
)
}
})
4 changes: 2 additions & 2 deletions core/parcel-transformer-svelte/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@plasmohq/parcel-transformer-svelte",
"version": "0.5.1",
"version": "0.5.2",
"description": "Plasmo Parcel Transformer for Svelte",
"files": [
"dist"
Expand All @@ -26,7 +26,7 @@
"tsup": "7.1.0"
},
"dependencies": {
"svelte": "4.0.0",
"svelte": "4.0.1",
"@parcel/core": "2.9.3",
"@parcel/diagnostic": "2.9.3",
"@parcel/plugin": "2.9.3",
Expand Down
7 changes: 6 additions & 1 deletion core/parcel-transformer-svelte/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ import { extendSourceMap } from "./source-map"
export default new Transformer({
async loadConfig({ config, options }) {
const conf = await config.getConfig(
[".svelterc", "svelte.config.js", "svelte.config.cjs"],
[
".svelterc",
"svelte.config.js",
"svelte.config.cjs",
"svelte.config.mjs"
],
{
packageKey: "svelte"
}
Expand Down
2 changes: 1 addition & 1 deletion examples
49 changes: 36 additions & 13 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1872f63

Please sign in to comment.