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

Fix revert vite 3 #773

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 10 additions & 17 deletions package.json
Expand Up @@ -48,17 +48,16 @@
"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.3",
"@playwright/test": "1.23.2",
"@types/cross-spawn": "6.0.2",
"@types/eslint": "8.4.5",
"@types/express": "4.17.13",
"@types/jest": "^28.1.5",
"@types/jest": "27.5.2",
"@types/mri": "1.1.1",
"@types/node": "latest",
"@types/node-fetch": "2.6.2",
Expand All @@ -73,26 +72,26 @@
"concurrently": "7.2.2",
"cross-spawn": "7.0.3",
"cz-conventional-changelog": "3.3.0",
"esbuild": "0.14.49",
"esbuild": "0.14.48",
"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": "28.1.3",
"jest": "27.5.1",
"mri": "1.2.0",
"node-fetch": "3.2.8",
"node-fetch": "2.6.7",
"path-browserify": "1.0.1",
"prettier": "2.7.1",
"rollup": "2.76.0",
"rollup": "2.75.7",
"semver": "7.3.7",
"tailwindcss": "3.1.6",
"terser": "5.14.2",
"terser": "5.14.1",
"todomvc-app-css": "2.4.2",
"todomvc-common": "1.0.5",
"ts-jest": "28.0.6",
"ts-jest": "27.1.5",
"typescript": "4.7.4",
"vite": "3.0.0",
"vite": "2.9.14",
"vite-tsconfig-paths": "3.5.0",
"wasm-pack": "0.10.3"
},
Expand Down Expand Up @@ -131,12 +130,7 @@
}
},
"jest": {
"preset": "ts-jest/presets/default-esm",
"globals": {
"ts-jest": {
"useESM": true
}
},
"preset": "ts-jest",
"moduleFileExtensions": [
"ts",
"tsx",
Expand All @@ -147,7 +141,6 @@
"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": "3.2.8",
"node-fetch": "2.6.7",
"postcss": "8.4.14",
"prism-themes": "1.9.0",
"prismjs": "^1.28.0",
"tailwindcss": "3.1.6",
"uvu": "0.5.6",
"vite": "3.0.0",
"vite": "2.9.14",
"wrangler": "beta"
},
"author": "Builder.io Team",
Expand Down
45 changes: 25 additions & 20 deletions packages/eslint-plugin-qwik/src/validLexicalScope.ts
@@ -1,7 +1,7 @@
/* eslint-disable no-console */
import { AST_NODE_TYPES, ESLintUtils } from '@typescript-eslint/utils';
import type { Scope } from '@typescript-eslint/utils/dist/ts-eslint-scope';
import { TypeChecker, Node, TypeFlags, Type, Symbol } from 'typescript';
import ts from 'typescript';
import type { Identifier } from 'estree';

const createRule = ESLintUtils.RuleCreator((name) => `https://typescript-eslint.io/rules/${name}`);
Expand Down Expand Up @@ -52,7 +52,7 @@ export const validLexicalScope = createRule({
const esTreeNodeToTSNodeMap = services.esTreeNodeToTSNodeMap;
const typeChecker = services.program.getTypeChecker();
const relevantScopes: Map<any, string> = new Map();
let exports: Symbol[] = [];
let exports: ts.Symbol[] = [];

function walkScope(scope: Scope) {
scope.references.forEach((ref) => {
Expand Down Expand Up @@ -167,13 +167,18 @@ export const validLexicalScope = createRule({
},
});

function canCapture(checker: TypeChecker, node: Node, ident: Identifier, opts: DetectorOptions) {
function canCapture(
checker: ts.TypeChecker,
node: ts.Node,
ident: Identifier,
opts: DetectorOptions
) {
const type = checker.getTypeAtLocation(node);
return isTypeCapturable(checker, type, node, ident, opts);
}

interface TypeReason {
type: Type;
type: ts.Type;
typeStr: string;
location?: string;
reason: string;
Expand All @@ -191,9 +196,9 @@ function humanizeTypeReason(reason: TypeReason) {
}

function isTypeCapturable(
checker: TypeChecker,
type: Type,
tsnode: Node,
checker: ts.TypeChecker,
type: ts.Type,
tsnode: ts.Node,
ident: Identifier,
opts: DetectorOptions
): TypeReason | undefined {
Expand All @@ -208,49 +213,49 @@ function isTypeCapturable(
return result;
}
function _isTypeCapturable(
checker: TypeChecker,
type: Type,
node: Node,
checker: ts.TypeChecker,
type: ts.Type,
node: ts.Node,
opts: DetectorOptions,
level: number
): TypeReason | undefined {
// NoSerialize is ok
if (type.getProperty('__no_serialize__')) {
return;
}
const isUnknown = type.flags & TypeFlags.Unknown;
const isUnknown = type.flags & ts.TypeFlags.Unknown;
if (isUnknown) {
return {
type,
typeStr: checker.typeToString(type),
reason: 'is unknown, which is not serializable',
};
}
const isAny = type.flags & TypeFlags.Any;
const isAny = type.flags & ts.TypeFlags.Any;
if (!opts.allowAny && isAny) {
return {
type,
typeStr: checker.typeToString(type),
reason: 'is any, which is not serializable',
};
}
const isBigInt = type.flags & TypeFlags.BigIntLike;
const isBigInt = type.flags & ts.TypeFlags.BigIntLike;
if (isBigInt) {
return {
type,
typeStr: checker.typeToString(type),
reason: 'is BigInt and it is not supported yet, use a number instead',
};
}
const isSymbol = type.flags & TypeFlags.ESSymbolLike;
const isSymbol = type.flags & ts.TypeFlags.ESSymbolLike;
if (isSymbol) {
return {
type,
typeStr: checker.typeToString(type),
reason: 'is Symbol, which is not serializable',
};
}
const isEnum = type.flags & TypeFlags.EnumLike;
const isEnum = type.flags & ts.TypeFlags.EnumLike;
if (isEnum) {
return {
type,
Expand All @@ -275,7 +280,7 @@ function _isTypeCapturable(
}
return;
}
const isObject = (type.flags & TypeFlags.Object) !== 0;
const isObject = (type.flags & ts.TypeFlags.Object) !== 0;
if (isObject) {
const symbolName = type.symbol.name;

Expand Down Expand Up @@ -340,16 +345,16 @@ function _isTypeCapturable(
}

function isSymbolCapturable(
checker: TypeChecker,
symbol: Symbol,
node: Node,
checker: ts.TypeChecker,
symbol: ts.Symbol,
node: ts.Node,
opts: DetectorOptions,
level: number
) {
const type = checker.getTypeOfSymbolAtLocation(symbol, node);
return _isTypeCapturable(checker, type, node, opts, level);
}

function getElementTypeOfArrayType(type: Type, checker: TypeChecker): Type | undefined {
function getElementTypeOfArrayType(type: ts.Type, checker: ts.TypeChecker): ts.Type | undefined {
return (checker as any).getElementTypeOfArrayType(type);
}
26 changes: 8 additions & 18 deletions packages/qwik-city/buildtime/vite/plugin.ts
Expand Up @@ -8,17 +8,7 @@ import { isMarkdownFileName, normalizePath } from '../utils/fs';
import { validatePlugin } from './validate-plugin';
import type { QwikCityVitePluginOptions } from './types';
import { build } from '../build';
import {
createPrinter,
createSourceFile,
factory,
isIdentifier,
isVariableDeclaration,
isVariableStatement,
NewLineKind,
ScriptTarget,
SyntaxKind,
} from 'typescript';
import ts from 'typescript';
import { configureDevServer } from './dev-server';

/**
Expand Down Expand Up @@ -115,38 +105,38 @@ export function qwikCity(userOpts?: QwikCityVitePluginOptions) {

function removeServerFns(code: string, id: string) {
let didModify = false;
const sourceFile = createSourceFile(id, code, ScriptTarget.Latest);
const sourceFile = ts.createSourceFile(id, code, ts.ScriptTarget.Latest);

for (const s of sourceFile.statements) {
if (!isVariableStatement(s)) {
if (!ts.isVariableStatement(s)) {
continue;
}

if (!s.modifiers?.some((m) => m.kind === SyntaxKind.ExportKeyword)) {
if (!s.modifiers?.some((m) => m.kind === ts.SyntaxKind.ExportKeyword)) {
continue;
}

const decs = s.declarationList.declarations;

for (const d of decs) {
if (!isVariableDeclaration(d)) {
if (!ts.isVariableDeclaration(d)) {
continue;
}
const identifier = d.name;
if (!isIdentifier(identifier)) {
if (!ts.isIdentifier(identifier)) {
continue;
}
if (!SERVER_FNS.some((fn) => identifier.escapedText === fn)) {
continue;
}

(d as any).initializer = factory.createNull();
(d as any).initializer = ts.factory.createNull();
didModify = true;
}
}

if (didModify) {
const printer = createPrinter({ newLine: NewLineKind.LineFeed });
const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });
return printer.printFile(sourceFile);
}
return null;
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": "3.0.0"
"vite": "2.9.14"
},
"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": "3.0.0"
"vite": "2.9.14"
},
"peerDependencies": {
"@builder.io/qwik": ">=0.0.35",
Expand Down
2 changes: 0 additions & 2 deletions packages/qwik/src/optimizer/src/api.md
Expand Up @@ -127,8 +127,6 @@ export interface OptimizerSystem {
os: string;
// (undocumented)
path: Path;
// (undocumented)
strictDynamicImport: (path: string) => Promise<any>;
}

// @alpha (undocumented)
Expand Down
9 changes: 1 addition & 8 deletions packages/qwik/src/optimizer/src/platform.ts
Expand Up @@ -18,11 +18,6 @@ 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 @@ -32,15 +27,14 @@ export async function getSystem() {
sys.path = createPath(sys);

if (globalThis.IS_ESM) {
sys.strictDynamicImport = sys.dynamicImport = (path) => import(path);
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 @@ -50,7 +44,6 @@ 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: 0 additions & 1 deletion packages/qwik/src/optimizer/src/plugins/plugin.unit.ts
Expand Up @@ -188,7 +188,6 @@ 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: 0 additions & 1 deletion packages/qwik/src/optimizer/src/plugins/rollup.unit.ts
Expand Up @@ -167,7 +167,6 @@ 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.ssr = {
(updatedViteConfig as any).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.strictDynamicImport('vite');
const { resolvePackageData }: typeof import('vite') = await sys.dynamicImport('vite');

try {
const data = await fs.promises.readFile(packageJsonPath, { encoding: 'utf-8' });
Expand Down