Skip to content

Commit

Permalink
make imports in .d.ts files relative
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich Harris committed May 10, 2023
1 parent 0d43af4 commit 803c300
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 12 deletions.
4 changes: 2 additions & 2 deletions packages/kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"sade": "^1.8.1",
"set-cookie-parser": "^2.6.0",
"sirv": "^2.0.2",
"tiny-glob": "^0.2.9",
"undici": "~5.22.0"
},
"devDependencies": {
Expand All @@ -37,6 +36,7 @@
"rollup": "^3.7.0",
"svelte": "^3.56.0",
"svelte-preprocess": "^5.0.3",
"tiny-glob": "^0.2.9",
"typescript": "^5.0.4",
"uvu": "^0.5.6",
"vite": "^4.3.0"
Expand Down Expand Up @@ -68,7 +68,7 @@
"test:cross-platform:build": "pnpm test:unit && pnpm -r --workspace-concurrency 1 --filter=\"./test/**\" test:cross-platform:build",
"test:unit": "uvu src \"(spec\\.js|test[\\\\/]index\\.js)\"",
"postinstall": "node postinstall.js",
"prepublishOnly": "tsc -p tsconfig.build.json && node scripts/copy-declaration-files"
"prepublishOnly": "tsc -p tsconfig.build.json && node scripts/process-declaration-files"
},
"exports": {
"./package.json": "./package.json",
Expand Down
5 changes: 0 additions & 5 deletions packages/kit/scripts/copy-declaration-files.js

This file was deleted.

24 changes: 24 additions & 0 deletions packages/kit/scripts/process-declaration-files.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import fs from 'node:fs';
import path from 'node:path';
import { copy } from '../src/utils/filesystem.js';
import glob from 'tiny-glob/sync.js';

glob('**/*.d.ts', { cwd: 'src' }).forEach((file) => {
fs.copyFileSync(`src/${file}`, `types/${file}`);
});

glob('types/**/*.d.ts').forEach((file) => {
// we need to rewrite `import('types')` as `import('../../types')` for anyone
// not using moduleResolution: 'bundler'

const dir = path.dirname(file);
const path_to_types = path.relative(dir, 'types/exports/types');
const path_to_public_types = path.relative(dir, 'types/types/public');

const contents = fs
.readFileSync(file, 'utf-8')
.replace(/import\('types'\)/g, `import('${path_to_types}')`)
.replace(/import\('@sveltejs\/kit'\)/g, `import('${path_to_public_types}')`);

fs.writeFileSync(file, contents);
});
4 changes: 2 additions & 2 deletions packages/kit/src/exports/hooks/sequence.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@
* first post-processing
* ```
*
* @param {...import('@sveltejs/kit').Handle} handlers The chain of `handle` functions
* @returns {import('@sveltejs/kit').Handle}
* @param {...import('types').Handle} handlers The chain of `handle` functions
* @returns {import('types').Handle}
*/
export function sequence(...handlers) {
const length = handlers.length;
Expand Down
6 changes: 3 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 803c300

Please sign in to comment.