Skip to content

Commit

Permalink
chore: cleanup after jsdoc (#659)
Browse files Browse the repository at this point in the history
* refactor: move types to .d.ts files in preparation of ts-to-jsdoc

* wip: convert ts to jsdoc

* wip: ts to jsdoc

* wip: ts to jsdoc conversion

* wip: finished jsdoc conversion, renamed .d.ts files to avoid collisions, added .js ext to imports

* test: add small wait for inspector icon to become visible to avoid flakiness in tests

* wip: move internal types into src/types, improve index.d.ts

* wip: move unit tests out of src dir and update filters

* chore: switch to eslint-plugin-n to get rid of some errors

* refactor: update jsdoc syntax (#656)

* refactor: rename prepared .ts files to .js, update scripts, add changeset

* fix: replace nullish assignment (requires node15) and enable error rules for invalid syntax that isn't downleveled anymore

* chore: fix types path

* remove tsup

* chore(types): replace rollup types with vite reexport

* chore: improve utility scripts, add publint

* chore: call check:types and check:publint in public packages via filter

* chore: disable tsc emit in inspector

* chore: remove noop build script

* chore: actually enable parallel processing for checks

---------

Co-authored-by: Bjorn Lu <[email protected]>
  • Loading branch information
dominikg and bluwy authored May 25, 2023
1 parent 9685a62 commit 01eb1b5
Show file tree
Hide file tree
Showing 23 changed files with 126 additions and 238 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module.exports = {
'n/no-extraneous-import': [
'error',
{
allowModules: ['vite']
allowModules: ['vite', 'vitest']
}
],
'n/no-extraneous-require': [
Expand Down
21 changes: 10 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,22 @@ jobs:
cache-dependency-path: '**/pnpm-lock.yaml'
- name: install
run: pnpm install --frozen-lockfile --prefer-offline --ignore-scripts
- name: build
id: build
run: pnpm build
- name: format
run: pnpm check:format
- name: lint
if: (${{ success() }} || ${{ failure() }})
run: pnpm lint
run: pnpm check:lint
- name: types
if: (${{ success() }} || ${{ failure() }})
run: pnpm check:types
- name: audit
if: (${{ success() }} || ${{ failure() }})
run: pnpm audit
run: pnpm check:audit
- name: publint
if: (${{ success() }} || ${{ failure() }})
run: pnpm check:publint

# this is the test matrix, it runs with node16 on linux,windows,macos + node14,18 on linux
# it is skipped if the build step of the checks job wasn't successful (still runs if lint or audit fail)
test:
needs: checks
if: (${{ success() }} || ${{ failure() }}) && (${{ needs.checks.output.build_successful }})
timeout-minutes: 10
runs-on: ${{ matrix.os }}
strategy:
Expand Down Expand Up @@ -111,8 +112,6 @@ jobs:
- name: install for node14
if: matrix.node == 14
run: pnpm install --no-frozen-lockfile --prefer-offline --ignore-scripts
- name: build
run: pnpm build
- name: install playwright chromium
run: pnpm playwright install chromium
- name: run tests
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ temp
**/temp
*.tmp
**/*.tmp
.eslintcache

# build and dist
build
Expand Down
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
aggregate-output=true
reporter=append-only
26 changes: 14 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@
"name": "vite-plugin-svelte-monorepo",
"private": true,
"scripts": {
"dev": "pnpm --dir packages/vite-plugin-svelte dev",
"build": "pnpm --dir packages/vite-plugin-svelte build",
"test": "run-s -c test:unit test:build test:serve",
"test:unit": "vitest run",
"test:serve": "vitest run -c vitest.config.e2e.ts",
"test:build": "cross-env TEST_BUILD=1 vitest run -c vitest.config.e2e.ts",
"lint": "eslint --ignore-path .gitignore '**/*.{js,ts,svelte,html,svx,md}'",
"lint:fix": "pnpm lint --fix",
"format": "prettier --ignore-path .gitignore '**/*.{css,scss,svelte,html,js,ts,svx,md}' --check",
"format:fix": "pnpm format --write",
"fixup": "run-s lint:fix format:fix",
"release": "pnpm build && pnpm changeset publish",
"check": "run-p -c check:*",
"check:audit": "pnpm audit --prod",
"check:publint": "pnpm --filter \"./packages/*\" --parallel check:publint",
"check:types": "pnpm --filter \"./packages/*\" --parallel check:types",
"check:lint": "eslint --cache --ignore-path .gitignore '**/*.{js,ts,svelte,html,svx,md}'",
"check:format": "prettier --cache --ignore-path .gitignore '**/*.{css,scss,svelte,html,js,ts,svx,md}' --check",
"lint": "pnpm check:lint --fix",
"format": "pnpm check:format --write",
"fixup": "run-s lint format",
"release": "pnpm changeset publish",
"prepare": "husky install"
},
"devDependencies": {
Expand Down Expand Up @@ -42,16 +44,17 @@
"playwright-core": "^1.33.0",
"prettier": "^2.8.8",
"prettier-plugin-svelte": "^2.10.0",
"publint": "^0.1.12",
"rimraf": "^5.0.0",
"svelte": "^3.59.1",
"typescript": "^5.0.4",
"vite": "^4.3.5",
"vitest": "^0.31.0"
},
"lint-staged": {
"*.{js,ts,svelte,html,md,svx}": "eslint --fix",
"*.{js,ts,svelte,html,md,svx}": "eslint --cache --fix",
"*.{css,scss,svelte,html,js,ts,svx,md}": [
"prettier --write"
"prettier --cache --write"
]
},
"packageManager": "[email protected]",
Expand All @@ -61,8 +64,7 @@
},
"pnpm": {
"overrides": {
"@sveltejs/vite-plugin-svelte": "workspace:^",
"tsup>postcss-load-config@<4": "^4.0.0"
"@sveltejs/vite-plugin-svelte": "workspace:^"
},
"peerDependencyRules": {
"allowedVersions": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "e2e-test-dep-svelte-nested",
"svelte": "src/index.js",
"main": "src/index.js",
"type": "module",
"files": [
"src"
],
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e-tests/vite-ssr/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
</head>
<body>
<div id="svelte"><!--app-outlet--></div>
<script type="module" src="/src/entry-client.js"></script>
<script type="module" src="/src/entry-client.mjs"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion packages/e2e-tests/vite-ssr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"dev": "node server",
"build": "pnpm build:client && pnpm build:server",
"build:client": "vite build --ssrManifest --outDir dist/client",
"build:server": "vite build --ssr src/entry-server.js --outDir dist/server",
"build:server": "vite build --ssr src/entry-server.mjs --outDir dist/server",
"preview": "cross-env NODE_ENV=production node server",
"debug": "node --inspect-brk server"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e-tests/vite-ssr/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ async function createServer(root = process.cwd(), isProd = process.env.NODE_ENV
// always read fresh template in dev
template = fs.readFileSync(resolve('index.html'), 'utf-8');
template = await vite.transformIndexHtml(url, template);
render = (await vite.ssrLoadModule('/src/entry-server.js')).render;
render = (await vite.ssrLoadModule('/src/entry-server.mjs')).render;
} else {
template = indexProd;
// @ts-ignore
Expand Down
4 changes: 4 additions & 0 deletions packages/vite-plugin-svelte-inspector/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
"import": "./src/index.js"
}
},
"scripts": {
"check:publint": "publint --strict",
"check:types": "tsc --noEmit"
},
"engines": {
"node": "^14.18.0 || >= 16"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-expect-error missing
// eslint-disable-next-line n/no-missing-import
import Inspector from 'virtual:svelte-inspector-path:Inspector.svelte';

Expand Down
6 changes: 4 additions & 2 deletions packages/vite-plugin-svelte-inspector/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"include": ["src"],
"exclude": ["**/*.spec.ts"],
"compilerOptions": {
"outDir": "dist",
"noEmit": true,
"target": "ES2020",
"module": "ES2020",
"moduleResolution": "node",
Expand All @@ -14,6 +14,8 @@
"baseUrl": ".",
"resolveJsonModule": true,
// see https://devblogs.microsoft.com/typescript/announcing-typescript-4-4-beta/#use-unknown-catch-variables
"useUnknownInCatchVariables": false
"useUnknownInCatchVariables": false,
"allowJs": true,
"checkJs": true
}
}
7 changes: 2 additions & 5 deletions packages/vite-plugin-svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
"./package.json": "./package.json"
},
"scripts": {
"dev": "pnpm typecheck --watch",
"build": "pnpm typecheck",
"typecheck": "tsc --noEmit --allowJs --checkJs"
"check:publint": "publint --strict",
"check:types": "tsc --noEmit"
},
"engines": {
"node": "^14.18.0 || >= 16"
Expand Down Expand Up @@ -54,9 +53,7 @@
"devDependencies": {
"@types/debug": "^4.1.7",
"esbuild": "^0.17.18",
"rollup": "^3.21.6",
"svelte": "^3.59.1",
"tsup": "^6.7.0",
"vite": "^4.3.5"
}
}
2 changes: 1 addition & 1 deletion packages/vite-plugin-svelte/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function svelte(inlineOptions) {
let compileSvelte;
/* eslint-enable no-unused-vars */

/** @type {Promise<import('rollup').PartialResolvedId | null>} */
/** @type {Promise<import('vite').Rollup.PartialResolvedId | null>} */
let resolvedSvelteSSR;
/** @type {Set<string>} */
let packagesWithResolveWarnings;
Expand Down
4 changes: 2 additions & 2 deletions packages/vite-plugin-svelte/src/utils/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { buildExtendedLogMessage } from './log.js';
* convert an error thrown by svelte.compile to a RollupError so that vite displays it in a user friendly way
* @param {import('svelte/types/compiler/interfaces').Warning & Error} error a svelte compiler error, which is a mix of Warning and an error
* @param {import('../types/options.d.ts').ResolvedOptions} options
* @returns {import('rollup').RollupError} the converted error
* @returns {import('vite').Rollup.RollupError} the converted error
*/
export function toRollupError(error, options) {
const { filename, frame, start, code, name, stack } = error;
/** @type {import('rollup').RollupError} */
/** @type {import('vite').Rollup.RollupError} */
const rollupError = {
name, // needed otherwise sveltekit coalesce_to_error turns it into a string
id: filename,
Expand Down
2 changes: 1 addition & 1 deletion packages/vite-plugin-svelte/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"include": ["src"],
"exclude": ["**/*.spec.ts"],
"compilerOptions": {
"outDir": "dist",
"noEmit": true,
"target": "ES2020",
"module": "ES2020",
"moduleResolution": "node",
Expand Down
Loading

0 comments on commit 01eb1b5

Please sign in to comment.