Skip to content

Commit

Permalink
chore: update to vite 3 (#766)
Browse files Browse the repository at this point in the history
  • Loading branch information
manucorporat committed Jul 14, 2022
1 parent fe4ad61 commit acb5d48
Show file tree
Hide file tree
Showing 13 changed files with 955 additions and 985 deletions.
27 changes: 17 additions & 10 deletions package.json
Expand Up @@ -48,16 +48,17 @@
"devDependencies": {
"@builder.io/partytown": "0.6.2",
"@builder.io/qwik-dom": "2.1.18",
"@jest/types": "^28.1.3",
"@microsoft/api-extractor": "7.28.4",
"@napi-rs/cli": "2.6.2",
"@napi-rs/triples": "1.1.0",
"@node-rs/helper": "1.3.3",
"@octokit/action": "3.18.1",
"@playwright/test": "1.23.2",
"@playwright/test": "1.23.3",
"@types/cross-spawn": "6.0.2",
"@types/eslint": "8.4.5",
"@types/express": "4.17.13",
"@types/jest": "27.5.2",
"@types/jest": "^28.1.5",
"@types/mri": "1.1.1",
"@types/node": "latest",
"@types/node-fetch": "2.6.2",
Expand All @@ -72,26 +73,26 @@
"concurrently": "7.2.2",
"cross-spawn": "7.0.3",
"cz-conventional-changelog": "3.3.0",
"esbuild": "0.14.48",
"esbuild": "0.14.49",
"esbuild-register": "3.3.3",
"eslint": "8.19.0",
"eslint-plugin-no-only-tests": "2.6.0",
"execa": "6.1.0",
"express": "4.18.1",
"jest": "27.5.1",
"jest": "28.1.3",
"mri": "1.2.0",
"node-fetch": "2.6.7",
"node-fetch": "3.2.8",
"path-browserify": "1.0.1",
"prettier": "2.7.1",
"rollup": "2.75.7",
"rollup": "2.76.0",
"semver": "7.3.7",
"tailwindcss": "3.1.6",
"terser": "5.14.1",
"terser": "5.14.2",
"todomvc-app-css": "2.4.2",
"todomvc-common": "1.0.5",
"ts-jest": "27.1.5",
"ts-jest": "28.0.6",
"typescript": "4.7.4",
"vite": "2.9.14",
"vite": "3.0.0",
"vite-tsconfig-paths": "3.5.0",
"wasm-pack": "0.10.3"
},
Expand Down Expand Up @@ -130,7 +131,12 @@
}
},
"jest": {
"preset": "ts-jest",
"preset": "ts-jest/presets/default-esm",
"globals": {
"ts-jest": {
"useESM": true
}
},
"moduleFileExtensions": [
"ts",
"tsx",
Expand All @@ -141,6 +147,7 @@
"d.ts"
],
"moduleNameMapper": {
"^(\\.{1,2}/.*)\\.js$": "$1",
"^@builder.io/qwik/jsx-runtime$": "<rootDir>/packages/qwik/src/jsx-runtime/index.ts",
"^@builder.io/qwik/optimizer$": "<rootDir>/packages/qwik/src/optimizer/index.ts",
"^@builder.io/qwik/server$": "<rootDir>/packages/qwik/src/server/index.ts",
Expand Down
4 changes: 2 additions & 2 deletions packages/docs/package.json
Expand Up @@ -24,13 +24,13 @@
"@cloudflare/kv-asset-handler": "0.2.0",
"autoprefixer": "10.4.7",
"fflate": "^0.7.3",
"node-fetch": "2.6.7",
"node-fetch": "3.2.8",
"postcss": "8.4.14",
"prism-themes": "1.9.0",
"prismjs": "^1.28.0",
"tailwindcss": "3.1.6",
"uvu": "0.5.6",
"vite": "2.9.14",
"vite": "3.0.0",
"wrangler": "beta"
},
"author": "Builder.io Team",
Expand Down
2 changes: 1 addition & 1 deletion packages/qwik-city/package.json
Expand Up @@ -70,7 +70,7 @@
"unified": "10.1.2",
"unist-util-visit": "4.1.0",
"uvu": "0.5.6",
"vite": "2.9.14"
"vite": "3.0.0"
},
"license": "MIT",
"homepage": "https://qwik.builder.io/",
Expand Down
2 changes: 1 addition & 1 deletion packages/qwik-react/package.json
Expand Up @@ -28,7 +28,7 @@
"react": "18.2.0",
"react-dom": "18.2.0",
"typescript": "4.7.4",
"vite": "2.9.14"
"vite": "3.0.0"
},
"peerDependencies": {
"@builder.io/qwik": ">=0.0.35",
Expand Down
2 changes: 2 additions & 0 deletions packages/qwik/src/optimizer/src/api.md
Expand Up @@ -127,6 +127,8 @@ export interface OptimizerSystem {
os: string;
// (undocumented)
path: Path;
// (undocumented)
strictDynamicImport: (path: string) => Promise<any>;
}

// @alpha (undocumented)
Expand Down
9 changes: 8 additions & 1 deletion packages/qwik/src/optimizer/src/platform.ts
Expand Up @@ -18,6 +18,11 @@ export async function getSystem() {
`Qwik Optimizer sys.dynamicImport() not implemented, trying to import: "${path}"`
);
},
strictDynamicImport: (path) => {
throw new Error(
`Qwik Optimizer sys.strictDynamicImport() not implemented, trying to import: "${path}"`
);
},
path: null as any,
cwd: () => '/',
os: 'unknown',
Expand All @@ -27,14 +32,15 @@ export async function getSystem() {
sys.path = createPath(sys);

if (globalThis.IS_ESM) {
sys.dynamicImport = (path) => import(path);
sys.strictDynamicImport = sys.dynamicImport = (path) => import(path);
}

if (globalThis.IS_CJS) {
if (sysEnv === 'node') {
// using this api object as a way to ensure bundlers
// do not try to inline or rewrite require()
sys.dynamicImport = (path) => require(path);
sys.strictDynamicImport = (path) => import(path);

if (typeof TextEncoder === 'undefined') {
// TextEncoder/TextDecoder needs to be on the global scope for the WASM file
Expand All @@ -44,6 +50,7 @@ export async function getSystem() {
global.TextDecoder = nodeUtil.TextDecoder;
}
} else if (sysEnv === 'webworker' || sysEnv === 'browsermain') {
sys.strictDynamicImport = (path) => import(path);
sys.dynamicImport = async (path: string) => {
const cjsRsp = await fetch(path);
const cjsCode = await cjsRsp.text();
Expand Down
1 change: 1 addition & 0 deletions packages/qwik/src/optimizer/src/plugins/plugin.unit.ts
Expand Up @@ -188,6 +188,7 @@ describe('qwik plugin', () => {
env: 'node',
os: process.platform,
dynamicImport: async (path) => require(path),
strictDynamicImport: async (path) => import(path),
path: require('path'),
},
binding: { mockBinding: true },
Expand Down
1 change: 1 addition & 0 deletions packages/qwik/src/optimizer/src/plugins/rollup.unit.ts
Expand Up @@ -167,6 +167,7 @@ describe('rollup plugin', () => {
env: 'node',
os: process.platform,
dynamicImport: async (path) => require(path),
strictDynamicImport: async (path) => import(path),
path: require('path'),
},
binding: { mockBinding: true },
Expand Down
6 changes: 3 additions & 3 deletions packages/qwik/src/optimizer/src/plugins/vite.ts
Expand Up @@ -236,9 +236,9 @@ export function qwikVite(qwikViteOpts: QwikVitePluginOptions = {}): any {
updatedViteConfig.build!.ssr = true;

if (viteCommand === 'serve') {
(updatedViteConfig as any).ssr = {
updatedViteConfig.ssr = {
noExternal: vendorIds,
} as any;
};
} else {
updatedViteConfig.publicDir = false;
}
Expand Down Expand Up @@ -617,7 +617,7 @@ const findQwikRoots = async (
): Promise<QwikPackages[]> => {
if (sys.env === 'node') {
const fs: typeof import('fs') = await sys.dynamicImport('fs');
const { resolvePackageData }: typeof import('vite') = await sys.dynamicImport('vite');
const { resolvePackageData }: typeof import('vite') = await sys.strictDynamicImport('vite');

try {
const data = await fs.promises.readFile(packageJsonPath, { encoding: 'utf-8' });
Expand Down
9 changes: 5 additions & 4 deletions packages/qwik/src/optimizer/src/plugins/vite.unit.ts
Expand Up @@ -52,7 +52,7 @@ describe('vite plugin', () => {
expect(c.optimizeDeps?.exclude).toEqual(excludeDeps);

expect(c.esbuild).toEqual(undefined);
expect((c as any).ssr).toBeUndefined();
expect(c.ssr).toBeUndefined();
});

it('command: serve, mode: production', async () => {
Expand Down Expand Up @@ -81,7 +81,7 @@ describe('vite plugin', () => {
expect(c.optimizeDeps?.include).toEqual(includeDeps);
expect(c.optimizeDeps?.exclude).toEqual(excludeDeps);
expect(c.esbuild).toEqual(undefined);
expect((c as any).ssr).toBeUndefined();
expect(c.ssr).toBeUndefined();
});
it('command: build, mode: development', async () => {
const plugin: VitePlugin = qwikVite(initOpts);
Expand Down Expand Up @@ -109,7 +109,7 @@ describe('vite plugin', () => {
expect(c.optimizeDeps?.include).toEqual(includeDeps);
expect(c.optimizeDeps?.exclude).toEqual(excludeDeps);
expect(c.esbuild).toEqual(undefined);
expect((c as any).ssr).toBeUndefined();
expect(c.ssr).toBeUndefined();
});

it('command: build, mode: production', async () => {
Expand Down Expand Up @@ -139,7 +139,7 @@ describe('vite plugin', () => {
expect(c.optimizeDeps?.include).toEqual(includeDeps);
expect(c.optimizeDeps?.exclude).toEqual(excludeDeps);
expect(c.esbuild).toEqual(undefined);
expect((c as any).ssr).toBeUndefined();
expect(c.ssr).toBeUndefined();
});

it('command: build, --mode production (client)', async () => {
Expand Down Expand Up @@ -218,6 +218,7 @@ describe('vite plugin', () => {
env: 'node',
os: process.platform,
dynamicImport: async (path) => require(path),
strictDynamicImport: async (path) => import(path),
path: require('path'),
},
binding: { mockBinding: true },
Expand Down
1 change: 1 addition & 0 deletions packages/qwik/src/optimizer/src/types.ts
Expand Up @@ -44,6 +44,7 @@ export interface OptimizerSystem {
env: SystemEnvironment;
os: string;
dynamicImport: (path: string) => Promise<any>;
strictDynamicImport: (path: string) => Promise<any>;
getInputFiles?: (rootDir: string) => Promise<TransformModuleInput[]>;
path: Path;
}
Expand Down
4 changes: 2 additions & 2 deletions scripts/binding-platform.ts
Expand Up @@ -51,7 +51,7 @@ export async function copyPlatformBindingWasm(config: BuildConfig) {
try {
const releaseDataUrl = `https://data.jsdelivr.com/v1/package/npm/@builder.io/qwik`;
const releaseRsp = await nodeFetch(releaseDataUrl);
const releases = await releaseRsp.json();
const releases = (await releaseRsp.json()) as any;
buildVersion = releases.tags.latest;
Object.values(releases.tags).forEach((version: any) => {
if (semver.gt(version, buildVersion)) {
Expand Down Expand Up @@ -87,7 +87,7 @@ export async function copyPlatformBindingWasm(config: BuildConfig) {

if (!existsSync(cachedPath)) {
const cdnUrl = `https://cdn.jsdelivr.net/npm/@builder.io/qwik@${buildVersion}/bindings/${bindingFilename}`;
const rsp = await nodeFetch(cdnUrl);
const rsp = (await nodeFetch(cdnUrl)) as any;
await writeFile(cachedPath, rsp.body);
}

Expand Down

0 comments on commit acb5d48

Please sign in to comment.