Skip to content

Commit

Permalink
Merge pull request #441 from preactjs/git-version
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinhagemeister authored Nov 20, 2022
2 parents d191702 + 9483559 commit 9a248b4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
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];
}

0 comments on commit 9a248b4

Please sign in to comment.