Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for loading preact from local repo #441

Merged
merged 1 commit into from
Nov 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
"test": "mochette -c tsconfig.cjs.json 'src/**/*.test.{ts,tsx}'",
"test:e2e": "node tools/fetch-preact-versions.mjs && playwright test",
"test:e2e:10": "PREACT_VERSION=10 npm run test:e2e",
"test:e2e:11": "PREACT_VERSION=11 npm run test:e2e",
"test:e2e:git": "PREACT_VERSION=git npm run test:e2e",
"test:e2e:all": "npm run test:e2e && npm run test:e2e:10",
"dev": "npm run dev:serve",
"dev:serve": "vite test-e2e/fixtures --port 8100",
Expand Down
26 changes: 25 additions & 1 deletion test-e2e/fixtures/load-preact-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,34 @@ export function loadPreactVersion(): Plugin {
if (match) {
const version = match[1].replace(/_/g, ".");

const versionDir = path.join(cacheDir, version);
if (cache.has(id)) {
return cache.get(id);
} else if (version === "git") {
const versionDir = path.join(process.cwd(), "..", "preact");
const pkg = JSON.parse(
fs.readFileSync(path.join(versionDir, "package.json"), "utf-8"),
);
const modName = id
.replace("@git", "")
.replace(/^preact$/, ".")
.replace(/^preact\//, "./");
const entry = pkg.exports[modName].module;

const code = fs.readFileSync(path.join(versionDir, entry), "utf-8");
const map = fs.readFileSync(
path.join(versionDir, entry + ".map"),
"utf-8",
);

return {
code: code.replace(
/["']preact/g,
`"preact@${version.replace(/\./g, "_")}`,
),
map,
};
} else {
const versionDir = path.join(cacheDir, version);
// Check if someone is already resolving
const inProgress = pending.get(version);
if (inProgress) {
Expand Down
4 changes: 3 additions & 1 deletion test-e2e/fixtures/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import fs from "fs";
*/
export function getPreactVersions() {
const dir = path.join(__dirname, "vendor", "preact");
return fs
const versions = fs
.readdirSync(dir)
.filter(name => !name.startsWith("."))
.map(name => {
Expand Down Expand Up @@ -50,4 +50,6 @@ export function getPreactVersions() {
// Check if is tagged release: 11.0.0-experimental.0
return a.localeCompare(b) * -1;
});

return ["git", ...versions];
}