Skip to content

Commit

Permalink
feat: upgrade parcel-bundler to align with latest (#307)
Browse files Browse the repository at this point in the history
* Upgrade parcel-bundler to the latest experimental

* Bump canary

* fix: add package command to index

* Try out sync config

* Remove template submod

* Fix up tag issue

* Update devs

* bump canary
  • Loading branch information
louisgv authored Nov 23, 2022
1 parent 48eb0fe commit b62a2fa
Show file tree
Hide file tree
Showing 32 changed files with 1,822 additions and 710 deletions.
4 changes: 0 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
path = packages/puro
url = [email protected]:PlasmoHQ/puro.git
branch = main
[submodule "templates/qtt"]
path = templates/qtt
url = [email protected]:PlasmoHQ/qtt.git
branch = main
[submodule "packages/gcp-refresh-token"]
path = packages/gcp-refresh-token
url = [email protected]:PlasmoHQ/gcp-refresh-token.git
Expand Down
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.59.1",
"version": "0.59.2-alpha.3",
"description": "Create Plasmo Framework Browser Extension",
"main": "dist/index.js",
"bin": "bin/index.mjs",
Expand Down
2 changes: 1 addition & 1 deletion cli/create-plasmo/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { version } from "plasmo/package.json"
import init from "plasmo/src/commands/init"
import { argv, exit } from "process"

import { ErrorMessage } from "@plasmo/constants"
import { ErrorMessage } from "@plasmo/constants/error"
import { aLog, eLog } from "@plasmo/utils/logging"
import { exitCountDown } from "@plasmo/utils/wait"

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.59.1",
"version": "0.59.2-alpha.3",
"description": "The Plasmo Platform CLI",
"main": "dist/index.js",
"types": "dist/type.d.ts",
Expand Down
3 changes: 0 additions & 3 deletions cli/plasmo/src/commands/build.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import { createWriteStream } from "fs"
import { resolve } from "path"

import { getNonFlagArgvs } from "@plasmo/utils/argv"
import { hasFlag } from "@plasmo/utils/flags"
import { iLog, sLog } from "@plasmo/utils/logging"
Expand Down
1 change: 1 addition & 0 deletions cli/plasmo/src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const runMap = {
init: () => import("./init"),
dev: () => import("./dev"),
build: () => import("./build"),
package: () => import("./package"),
//#endif

version: () => import("./version"),
Expand Down
4 changes: 3 additions & 1 deletion cli/plasmo/src/features/extension-devtools/common-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import { existsSync } from "fs"
import { basename, resolve } from "path"
import { cwd } from "process"

import { flagMap } from "~features/helpers/flag"
import { getFlagMap } from "~features/helpers/flag"

export const getCommonPath = (projectDirectory = cwd()) => {
const flagMap = getFlagMap()

process.env.PLASMO_PROJECT_DIR = projectDirectory

const packageName = basename(projectDirectory)
Expand Down
10 changes: 6 additions & 4 deletions cli/plasmo/src/features/extension-devtools/generate-icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import sharp from "sharp"

import { vLog, wLog } from "@plasmo/utils/logging"

import { flagMap } from "~features/helpers/flag"
import { getFlagMap } from "~features/helpers/flag"

import type { CommonPath } from "./common-path"

Expand All @@ -28,16 +28,18 @@ const baseIconNames = [
* 3. plain icon
*
* */
const getPrioritizedIconPaths = (iconNames = baseIconNames) =>
iconNames
const getPrioritizedIconPaths = (iconNames = baseIconNames) => {
const flagMap = getFlagMap()

return iconNames
.map((name) => [
`${name}.${flagMap.tag}.${process.env.NODE_ENV}.png`,
`${name}.${process.env.NODE_ENV}.png`,
`${name}.${flagMap.tag}.png`,
`${name}.png`
])
.flat()

}
// Use this to cache the path resolving result
const iconState = {
baseIconPaths: [] as string[],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { flagMap } from "~features/helpers/flag"

const { target, tag } = flagMap

export const [browser, manifestVersion] = target.split("-")
import { getFlagMap } from "~features/helpers/flag"

export const getBundleConfig = () => {
const flagMap = getFlagMap()
const { target, tag } = flagMap
const [browser, manifestVersion] = target.split("-")
// Potential runtime config here
return {
tag,
Expand Down
8 changes: 4 additions & 4 deletions cli/plasmo/src/features/extension-devtools/load-env-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import { join } from "path"

import { eLog, iLog } from "@plasmo/utils/logging"

import { browser } from "~features/extension-devtools/get-bundle-config"
import { flagMap } from "~features/helpers/flag"
import { getFlagMap } from "~features/helpers/flag"

export type Env = Record<string, string | undefined>
export type LoadedEnvFiles = Array<{
Expand Down Expand Up @@ -78,11 +77,12 @@ function processEnv(loadedEnvFiles: LoadedEnvFiles, dir?: string) {

export async function loadEnvConfig(dir: string) {
const nodeEnv = process.env.NODE_ENV
const flagMap = getFlagMap()

const dotenvFilePaths = [
flagMap.envPath,

`.env.${browser}.local`,
`.env.${flagMap.browser}.local`,
`.env.${flagMap.tag}.local`,
`.env.${nodeEnv}.local`,

Expand All @@ -91,7 +91,7 @@ export async function loadEnvConfig(dir: string) {
// results for everyone
nodeEnv !== "test" ? `.env.local` : "",

`.env.${browser}`,
`.env.${flagMap.browser}`,
`.env.${flagMap.tag}`,
`.env.${nodeEnv}`,
".env"
Expand Down
44 changes: 25 additions & 19 deletions cli/plasmo/src/features/helpers/flag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,37 @@ import { paramCase } from "change-case"

import { getFlag } from "@plasmo/utils/flags"

const srcPath = getFlag("--src-path") || process.env.PLASMO_SRC_PATH || "src"
export const getFlagMap = () => {
const srcPath = getFlag("--src-path") || process.env.PLASMO_SRC_PATH || "src"

const buildPath =
getFlag("--build-path") || process.env.PLASMO_BUILD_PATH || "build"
const buildPath =
getFlag("--build-path") || process.env.PLASMO_BUILD_PATH || "build"

const tag =
getFlag("--tag") ||
process.env.PLASMO_TAG ||
(process.env.NODE_ENV === "production" ? "prod" : "dev")
const tag =
getFlag("--tag") ||
process.env.PLASMO_TAG ||
(process.env.NODE_ENV === "production" ? "prod" : "dev")

const target = paramCase(
getFlag("--target") || process.env.PLASMO_TARGET || "chrome-mv3"
)
const target = paramCase(
getFlag("--target") || process.env.PLASMO_TARGET || "chrome-mv3"
)

const entry = getFlag("--entry") || "popup"
const [browser, manifestVersion] = target.split("-")

const envPath = getFlag("--env")
const entry = getFlag("--entry") || "popup"

export const flagMap = {
tag,
srcPath,
buildPath,
target,
entry,
envPath
const envPath = getFlag("--env")

return {
browser,
manifestVersion,
tag,
srcPath,
buildPath,
target,
entry,
envPath
}
}

export const flagHelp = `
Expand Down
5 changes: 1 addition & 4 deletions cli/plasmo/src/features/manifest-factory/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ import {
ProjectPath,
getProjectPath
} from "~features/extension-devtools/project-path"
import {
TemplatePath,
getTemplatePath
} from "~features/extension-devtools/template-path"
import { getTemplatePath } from "~features/extension-devtools/template-path"
import { updateVersionFile } from "~features/framework-update/version-tracker"
import { getSubExt, toPosix } from "~features/helpers/path"
import { definedTraverse } from "~features/helpers/traverse"
Expand Down
2 changes: 2 additions & 0 deletions cli/plasmo/templates/plasmo.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ declare namespace NodeJS {

PLASMO_TARGET:
| `${ProcessEnv["PLASMO_BROWSER"]}-${ProcessEnv["PLASMO_MANIFEST_VERSION"]}`

PLASMO_TAG: string
}
}

Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"workspaces": [
"cli/*",
"packages/*",
"templates/*",
"examples/*"
],
"scripts": {
Expand Down Expand Up @@ -41,12 +40,12 @@
"@types/semver": "7.3.13",
"@types/sharp": "0.31.0",
"@types/uuid": "8.3.4",
"esbuild": "0.15.14",
"esbuild": "0.15.15",
"eslint": "8.28.0",
"eslint-config-prettier": "8.5.0",
"eslint-plugin-react": "7.31.11",
"fs-extra": "10.1.0",
"prettier": "2.7.1",
"prettier": "2.8.0",
"tsup": "6.5.0",
"turbo": "1.6.3"
},
Expand Down
3 changes: 2 additions & 1 deletion packages/parcel-bundler/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@plasmohq/parcel-bundler",
"version": "0.3.0",
"version": "0.4.0",
"license": "MIT",
"repository": {
"type": "git",
Expand All @@ -19,6 +19,7 @@
},
"dependencies": {
"@parcel/core": "2.8.0",
"@parcel/graph": "2.8.0",
"@parcel/diagnostic": "2.8.0",
"@parcel/hash": "2.8.0",
"@parcel/plugin": "2.8.0",
Expand Down
10 changes: 10 additions & 0 deletions packages/parcel-bundler/src/can-merge.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export function canMerge(a, b) {
// Bundles can be merged if they have the same type and environment,
// unless they are explicitly marked as isolated or inline.
return (
a.type === b.type &&
a.env.context === b.env.context &&
a.bundleBehavior == null &&
b.bundleBehavior == null
)
}
45 changes: 45 additions & 0 deletions packages/parcel-bundler/src/create-bundle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import type { Asset, BundleBehavior, Environment, Target } from "@parcel/types"
import nullthrows from "nullthrows"

import type { Bundle } from "./types"

export function createBundle(opts: {
uniqueKey?: string
target: Target
asset?: Asset
env?: Environment
type?: string
needsStableName?: boolean
bundleBehavior?: BundleBehavior | null | undefined
}): Bundle {
if (opts.asset == null) {
return {
uniqueKey: opts.uniqueKey,
assets: new Set(),
internalizedAssetIds: [],
mainEntryAsset: null,
size: 0,
sourceBundles: new Set(),
target: opts.target,
type: nullthrows(opts.type),
env: nullthrows(opts.env),
needsStableName: Boolean(opts.needsStableName),
bundleBehavior: opts.bundleBehavior
}
}

let asset = nullthrows(opts.asset)
return {
uniqueKey: opts.uniqueKey,
assets: new Set([asset]),
internalizedAssetIds: [],
mainEntryAsset: asset,
size: asset.stats.size,
sourceBundles: new Set(),
target: opts.target,
type: opts.type ?? asset.type,
env: opts.env ?? asset.env,
needsStableName: Boolean(opts.needsStableName),
bundleBehavior: opts.bundleBehavior ?? asset.bundleBehavior
}
}
Loading

0 comments on commit b62a2fa

Please sign in to comment.