Skip to content

Commit

Permalink
Merge pull request #7 from marko-js/move-away-from-tla
Browse files Browse the repository at this point in the history
Move away from tla
  • Loading branch information
DylanPiercey authored Nov 30, 2023
2 parents 03143ae + 1472478 commit ec6ed21
Show file tree
Hide file tree
Showing 15 changed files with 514 additions and 444 deletions.
5 changes: 5 additions & 0 deletions .changeset/curvy-bags-invent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"arc-vite": patch
---

Avoid using `this.load` unless the ast has not already been parsed for a module.
5 changes: 5 additions & 0 deletions .changeset/good-masks-float.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"arc-vite": minor
---

Move away from top level await which has limited browser support.
5 changes: 5 additions & 0 deletions .changeset/grumpy-pigs-smile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"arc-vite": patch
---

Avoid checking for virtual adaptive modules when processing files known to be handled by Vite.
568 changes: 272 additions & 296 deletions package-lock.json

Large diffs are not rendered by default.

31 changes: 15 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,40 +37,39 @@
"lint": "npm run build && eslint -f unix && prettier . --check --log-level=warn && sort-package-json --quiet --check",
"prepare": "husky install",
"release": "npm run build && changeset publish",
"test": "tsx --test-reporter=spec --test ./src/tests/*.test.ts",
"test": "MARKO_DEBUG=true tsx --test-reporter=spec --test ./src/tests/*.test.ts",
"version": "changeset version && npm i --package-lock-only"
},
"dependencies": {
"arc-resolver": "^3.0.0",
"domelementtype": "^2.3.0",
"domhandler": "^5.0.3",
"dom-serializer": "^2.0.0",
"htmlparser2": "^9.0.0"
},
"devDependencies": {
"@changesets/changelog-github": "^0.4.8",
"@changesets/cli": "^2.26.2",
"@marko/compiler": "^5.33.8",
"@marko/vite": "^4.0.2",
"@playwright/test": "^1.39.0",
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "^2.27.1",
"@marko/compiler": "^5.34.1",
"@marko/vite": "^4.1.1",
"@playwright/test": "^1.40.1",
"@types/estree": "^1.0.5",
"@types/node": "^20.9.0",
"@types/node": "^20.10.1",
"@types/serve-handler": "^6.1.4",
"@typescript-eslint/eslint-plugin": "^6.11.0",
"@typescript-eslint/parser": "^6.11.0",
"@typescript-eslint/eslint-plugin": "^6.13.1",
"@typescript-eslint/parser": "^6.13.1",
"c8": "^8.0.1",
"eslint": "^8.53.0",
"eslint": "^8.54.0",
"eslint-config-prettier": "^9.0.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-import": "^2.29.0",
"husky": "^8.0.3",
"lint-staged": "^15.1.0",
"marko": "^5.31.18",
"playwright": "^1.39.0",
"marko": "^5.32.0",
"playwright": "^1.40.1",
"prettier": "^3.1.0",
"serve-handler": "^6.1.5",
"sort-package-json": "^2.6.0",
"tsx": "^4.1.2",
"typescript": "^5.2.2",
"tsx": "^4.6.1",
"typescript": "^5.3.2",
"vite": "^4.5.0"
},
"peerDependencies": {
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { Plugin } from "vite";
import { pluginBuildSSR } from "./plugins/build-ssr";
import { pluginBuildWeb } from "./plugins/build-web";
import { pluginServe } from "./plugins/serve";
import type { FlagSet } from "./utils/flags";
import { type Options, getInternalPluginOptions } from "./utils/options";

export { createFlagSets, hasFlags } from "./utils/flags";
Expand Down Expand Up @@ -35,6 +36,7 @@ declare module "rollup" {
arcSourceId?: string;
arcSourceCode?: string;
arcScanIds?: string[];
arcFlagSet?: FlagSet;
arcFS?: typeof import("fs");
}
}
41 changes: 25 additions & 16 deletions src/plugins/build-ssr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ export function pluginBuildSSR({
const matches = await getVirtualMatches(this, flagSets, resolved);
if (matches) {
const { id } = resolved;
if (!this.getModuleInfo(id)?.ast) {
await this.load(resolved);
}

adaptiveMatchesForId.set(id, matches);
return { id: encodeArcProxyId(id) };
}
Expand Down Expand Up @@ -131,22 +135,22 @@ function partsToString(parts, base, injectAttrs) {
id = decodeArcProxyId(id);
const adaptiveMatches = adaptiveMatchesForId.get(id);
if (adaptiveMatches) {
const info = await this.load({ id });
if (info) {
if (isCssFile(id)) {
let code = "";
for (const { value } of adaptiveMatches.alternates) {
code += `import ${JSON.stringify(value)};\n`;
}
if (isCssFile(id)) {
let code = "";
for (const { value } of adaptiveMatches.alternates) {
code += `import ${JSON.stringify(value)};\n`;
}

code += `import ${JSON.stringify(adaptiveMatches.default)};\n`;
code += `import ${JSON.stringify(adaptiveMatches.default)};\n`;

return {
code,
moduleSideEffects: "no-treeshake",
};
}
return {
code,
moduleSideEffects: "no-treeshake",
};
}

const info = this.getModuleInfo(id);
if (info) {
let code = "";
let matchCode = "";
let matchCodeSep = "";
Expand Down Expand Up @@ -205,16 +209,21 @@ function partsToString(parts, base, injectAttrs) {
}
}
} else if (isArcVirtualMatch(id)) {
const [arcSourceId, flagSet] = decodeArcVirtualMatch(id);
const [arcSourceId, arcFlagSet] = decodeArcVirtualMatch(id);
const { meta, moduleSideEffects, syntheticNamedExports } =
this.getModuleInfo(arcSourceId)!;
const code = meta.arcSourceCode as string;
const arcFS = getArcFS(flagSet);
const arcFS = getArcFS(arcFlagSet);
return {
code,
moduleSideEffects,
syntheticNamedExports,
meta: { ...meta, arcSourceId, arcFS },
meta: {
...meta,
arcSourceId,
arcFlagSet,
arcFS,
},
};
}

Expand Down
Loading

0 comments on commit ec6ed21

Please sign in to comment.