Skip to content

Commit

Permalink
feat: implement Node ESM loader (#17)
Browse files Browse the repository at this point in the history
* feat: implement Node ESM loader

* feat: implement cli dev comment

* chore: bump version numbers

* fix: path separators on windows

* fix: resolved URL construction on Windows

* chore: clean up

* feat: make qwik work

* chore: update docs
  • Loading branch information
cyco130 authored Feb 27, 2023
1 parent 32697cb commit 7187a45
Show file tree
Hide file tree
Showing 45 changed files with 2,217 additions and 1,395 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,5 @@ dist
# Local files
*.local.*

# Packed package files
*.tgz
105 changes: 46 additions & 59 deletions ci/ci.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,75 +18,63 @@ const browser = await puppeteer.launch({
const pages = await browser.pages();
const page = pages[0];

const cases = [
{
framework: "simple-standalone",
env: "development",
file: "handler.ts",
},

{ framework: "simple-standalone", env: "production", file: "handler.ts" },

{ framework: "express", env: "development", file: "routes/home.ts" },
{ framework: "express", env: "production", file: "routes/home.ts" },

{ framework: "fastify", env: "development", file: "routes/home.ts" },
{ framework: "fastify", env: "production", file: "routes/home.ts" },

{ framework: "koa", env: "development", file: "routes/home.ts" },
{ framework: "koa", env: "production", file: "routes/home.ts" },

{ framework: "hapi", env: "development", file: "routes/home.ts" },
{ framework: "hapi", env: "production", file: "routes/home.ts" },

{
framework: "ssr-react-express",
env: "development",
file: "pages/Home.tsx",
},
{
framework: "ssr-react-express",
env: "production",
file: "pages/Home.tsx",
},
{
framework: "ssr-vue-express",
env: "development",
file: "pages/Home.vue",
},
{
framework: "ssr-vue-express",
env: "production",
file: "pages/Home.vue",
},
{
framework: "vite-plugin-ssr",
env: "development",
file: "pages/index/index.page.tsx",
},
{
framework: "vite-plugin-ssr",
env: "production",
file: "pages/index/index.page.tsx",
},
] as const;

describe.each(cases)("$framework - $env", ({ framework, env, file }) => {
const baseCases: Array<{
framework: string;
file: string;
}> = [
{ framework: "simple-standalone", file: "handler.ts" },
{ framework: "express", file: "routes/home.ts" },
{ framework: "fastify", file: "routes/home.ts" },
{ framework: "koa", file: "routes/home.ts" },
{ framework: "hapi", file: "routes/home.ts" },
{ framework: "ssr-react-express", file: "pages/Home.tsx" },
{ framework: "ssr-vue-express", file: "pages/Home.vue" },
{ framework: "vite-plugin-ssr", file: "pages/index/index.page.tsx" },
];

const [major, minor] = process.version
.slice(1)
.split(".")
.map((x) => Number(x));

const cases: Array<{
framework: string;
file: string;
env: "production" | "development" | "with-loader";
}> = [
...baseCases.map((x) => ({ ...x, env: "production" as const })),
...baseCases.map((x) => ({ ...x, env: "development" as const })),
];

const loaderAvailable = major > 16 || (major === 16 && minor >= 12);
if (loaderAvailable) {
cases.push(...baseCases.map((x) => ({ ...x, env: "with-loader" as const })));
}

describe.each(cases)("$framework - $env ", ({ framework, env, file }) => {
const ssr = framework.includes("ssr");
const dir = path.resolve(__dirname, "..", "examples", framework);

let cp: ChildProcess | undefined;

beforeAll(async () => {
const command =
env === "development"
? "pnpm exec vite serve --strictPort --port 3000 --logLevel silent"
: "pnpm run build && pnpm start";
env === "production"
? "pnpm run build && pnpm start"
: "pnpm exec vite serve --strictPort --port 3000 --logLevel silent";

cp = spawn(command, {
shell: true,
stdio: "inherit",
cwd: dir,
env: {
...process.env,
...(env === "with-loader" && {
NODE_OPTIONS:
(process.env.NODE_OPTIONS ?? "") +
" -r vavite/suppress-loader-warnings --loader vavite/node-loader",
}),
},
});

// Wait until server is ready
Expand Down Expand Up @@ -134,7 +122,6 @@ describe.each(cases)("$framework - $env", ({ framework, env, file }) => {

test("renders home page", async () => {
const text = await fetch(TEST_HOST).then((r) => r.text());
if (!text.includes("Hello")) console.log(text);
expect(text).toContain("Hello");
}, 10_000);

Expand All @@ -155,7 +142,7 @@ describe.each(cases)("$framework - $env", ({ framework, env, file }) => {
}, 15_000);
}

if (env === "development") {
if (env !== "production") {
test("hot reloads page", async () => {
await page.goto(TEST_HOST);

Expand Down
8 changes: 4 additions & 4 deletions ci/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
"ci": "vitest run --reporter=verbose --no-threads"
},
"dependencies": {
"@types/node": "^18.11.18",
"@types/node": "^18.14.1",
"kill-port": "^2.0.1",
"node-fetch": "^3.3.0",
"ps-tree": "^1.2.0",
"puppeteer": "^19.5.2",
"typescript": "^4.9.4",
"vitest": "^0.27.1"
"puppeteer": "^19.7.2",
"typescript": "^4.9.5",
"vitest": "^0.28.5"
},
"devDependencies": {
"@types/ps-tree": "^1.1.2"
Expand Down
10 changes: 5 additions & 5 deletions examples/express/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
"dist"
],
"devDependencies": {
"@types/express": "^4.17.15",
"@types/node": "^18.11.18",
"typescript": "^4.9.4",
"vavite": "1.5.3",
"vite": "^4.0.4"
"@types/express": "^4.17.17",
"@types/node": "^18.14.1",
"typescript": "^4.9.5",
"vavite": "1.6.0",
"vite": "^4.1.4"
},
"dependencies": {
"express": "^4.18.2"
Expand Down
24 changes: 12 additions & 12 deletions examples/fastify-vite-plugin-ssr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@
"type": "module",
"private": true,
"scripts": {
"dev": "vite",
"build": "vavite",
"dev": "vavite serve",
"build": "vavite build",
"start": "node dist/server"
},
"dependencies": {
"@fastify/static": "^6.6.1",
"@types/node": "^18.11.18",
"@types/react": "^18.0.26",
"@types/react-dom": "^18.0.10",
"@vitejs/plugin-react": "^3.0.1",
"@fastify/static": "^6.9.0",
"@types/node": "^18.14.1",
"@types/react": "^18.0.28",
"@types/react-dom": "^18.0.11",
"@vitejs/plugin-react": "^3.1.0",
"cross-env": "^7.0.3",
"fastify": "^4.11.0",
"fastify": "^4.13.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"ts-node": "^10.9.1",
"typescript": "^4.9.4",
"vavite": "1.5.3",
"vite": "^4.0.4",
"vite-plugin-ssr": "^0.4.69"
"typescript": "^4.9.5",
"vavite": "1.6.0",
"vite": "^4.1.4",
"vite-plugin-ssr": "^0.4.88"
}
}
10 changes: 5 additions & 5 deletions examples/fastify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
"dist"
],
"devDependencies": {
"@types/node": "^18.11.18",
"typescript": "^4.9.4",
"vavite": "1.5.3",
"vite": "^4.0.4"
"@types/node": "^18.14.1",
"typescript": "^4.9.5",
"vavite": "1.6.0",
"vite": "^4.1.4"
},
"dependencies": {
"fastify": "^4.11.0"
"fastify": "^4.13.0"
}
}
10 changes: 5 additions & 5 deletions examples/hapi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
],
"devDependencies": {
"@types/hapi__hapi": "^21.0.0",
"@types/node": "^18.11.18",
"typescript": "^4.9.4",
"vavite": "1.5.3",
"vite": "^4.0.4"
"@types/node": "^18.14.1",
"typescript": "^4.9.5",
"vavite": "1.6.0",
"vite": "^4.1.4"
},
"dependencies": {
"@hapi/hapi": "^21.2.0"
"@hapi/hapi": "^21.3.0"
}
}
8 changes: 4 additions & 4 deletions examples/koa/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
"devDependencies": {
"@types/koa": "^2.13.5",
"@types/koa__router": "^12.0.0",
"@types/node": "^18.11.18",
"typescript": "^4.9.4",
"vavite": "1.5.3",
"vite": "^4.0.4"
"@types/node": "^18.14.1",
"typescript": "^4.9.5",
"vavite": "1.6.0",
"vite": "^4.1.4"
},
"dependencies": {
"@koa/router": "^12.0.0",
Expand Down
36 changes: 18 additions & 18 deletions examples/nestjs-vite-plugin-ssr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,36 @@
"private": true,
"type": "module",
"scripts": {
"start": "node dist/server",
"dev": "vite",
"build": "vavite"
"dev": "vavite serve",
"build": "vavite build",
"start": "node dist/server"
},
"files": [
"dist"
],
"devDependencies": {
"@swc/core": "^1.3.26",
"@types/express": "^4.17.15",
"@types/node": "^18.11.18",
"@types/react": "^18.0.26",
"@types/react-dom": "^18.0.10",
"@vitejs/plugin-react": "^3.0.1",
"@swc/core": "^1.3.36",
"@types/express": "^4.17.17",
"@types/node": "^18.14.1",
"@types/react": "^18.0.28",
"@types/react-dom": "^18.0.11",
"@vitejs/plugin-react": "^3.1.0",
"rollup-plugin-swc3": "^0.8.0",
"typescript": "^4.9.4",
"vavite": "1.5.3",
"vite": "^4.0.4",
"vite-tsconfig-paths": "^4.0.3"
"typescript": "^4.9.5",
"vavite": "1.6.0",
"vite": "^4.1.4",
"vite-tsconfig-paths": "^4.0.5"
},
"dependencies": {
"@nestjs/common": "^9.2.1",
"@nestjs/core": "^9.2.1",
"@nestjs/platform-express": "^9.2.1",
"@nestjs/serve-static": "^3.0.0",
"@nestjs/common": "^9.3.9",
"@nestjs/core": "^9.3.9",
"@nestjs/platform-express": "^9.3.9",
"@nestjs/serve-static": "^3.0.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-streaming": "0.3.5",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.8.0",
"vite-plugin-ssr": "^0.4.69"
"vite-plugin-ssr": "^0.4.88"
}
}
18 changes: 9 additions & 9 deletions examples/nestjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@
"dist"
],
"devDependencies": {
"@swc/core": "^1.3.26",
"@types/express": "^4.17.15",
"@types/node": "^18.11.18",
"@swc/core": "^1.3.36",
"@types/express": "^4.17.17",
"@types/node": "^18.14.1",
"rollup-plugin-swc3": "^0.8.0",
"typescript": "^4.9.4",
"vavite": "1.5.3",
"vite": "^4.0.4"
"typescript": "^4.9.5",
"vavite": "1.6.0",
"vite": "^4.1.4"
},
"dependencies": {
"@nestjs/common": "^9.2.1",
"@nestjs/core": "^9.2.1",
"@nestjs/platform-express": "^9.2.1",
"@nestjs/common": "^9.3.9",
"@nestjs/core": "^9.3.9",
"@nestjs/platform-express": "^9.3.9",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.8.0"
}
Expand Down
10 changes: 5 additions & 5 deletions examples/simple-standalone/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"private": true,
"scripts": {
"start": "node dist",
"dev": "vite",
"dev": "vavite serve",
"build": "vite build --ssr --mode=production"
},
"devDependencies": {
"@types/node": "^18.11.18",
"typescript": "^4.9.4",
"vavite": "1.5.3",
"vite": "^4.0.4"
"@types/node": "^18.14.1",
"typescript": "^4.9.5",
"vavite": "1.6.0",
"vite": "^4.1.4"
}
}
12 changes: 6 additions & 6 deletions examples/socket-io/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
"dist"
],
"devDependencies": {
"@types/express": "^4.17.15",
"@types/node": "^18.11.18",
"typescript": "^4.9.4",
"vavite": "1.5.3",
"vite": "^4.0.4"
"@types/express": "^4.17.17",
"@types/node": "^18.14.1",
"typescript": "^4.9.5",
"vavite": "1.6.0",
"vite": "^4.1.4"
},
"dependencies": {
"express": "^4.18.2",
"socket.io": "^4.5.4"
"socket.io": "^4.6.1"
}
}
Loading

0 comments on commit 7187a45

Please sign in to comment.