Skip to content

Commit

Permalink
Use the correct imports in the generated .d.ts files (#1742)
Browse files Browse the repository at this point in the history
When using @wp-playground/client with TypeScript, the IDE doesn't seem
to be able to recognize types. This is because the published types
contain fragments such as:

```ts
import { Emscripten, MountHandler, PHP } from '../../../universal';
```

Which are relative to the build directory on the building machine.

This PR sets the `pathsToAliases` option of the `vite-dts-plugin` to
false to retain the packages names in those declaration files.

```ts
import { Emscripten, MountHandler, PHP } from '@php-wasm/universal';
```

 ## Testing instruction

Run `npm run build` and grep the `dist` directory for `../../`. There
should be no matches:

```sh
grep '\.\./\.\./' -R ./ | grep '\.d\.ts' | grep import
```

Inspect a few files, such as
`dist/packages/php-wasm/web/lib/get-php-loader-module.d.ts`, and confirm
they import from the proper package names.

Closes #1725

cc @brandonpayton
  • Loading branch information
adamziel authored Sep 9, 2024
1 parent db78ea4 commit 2461532
Show file tree
Hide file tree
Showing 19 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/php-wasm/fs-journal/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default defineConfig({
dts({
entryRoot: 'src',
tsconfigPath: join(__dirname, 'tsconfig.lib.json'),
pathsToAliases: false,
}),

viteTsConfigPaths({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { UniversalPHP, PHPRequestErrorEvent } from '../../universal';
import type { UniversalPHP, PHPRequestErrorEvent } from '../types';
import { Logger } from '../logger';

let lastPHPLogLength = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface UniversalPHP {

addEventListener(
event: string,
listener: (event: PHPRequestEndEvent | PHPRequestErrorEvent) => void
listener: (event: PHPRequestErrorEvent) => void
): void;
}

Expand Down
3 changes: 2 additions & 1 deletion packages/php-wasm/logger/tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"src/**/*.spec.js",
"src/**/*.test.jsx",
"src/**/*.spec.jsx",
"src/**/*.d.ts"
"src/**/*.d.ts",
"src/types.ts"
]
}
1 change: 1 addition & 0 deletions packages/php-wasm/logger/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default defineConfig({
dts({
entryRoot: 'src',
tsconfigPath: join(__dirname, 'tsconfig.lib.json'),
pathsToAliases: false,
}),

viteTsConfigPaths({
Expand Down
1 change: 1 addition & 0 deletions packages/php-wasm/node-polyfills/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default defineConfig({
dts({
entryRoot: 'src',
tsconfigPath: join(__dirname, 'tsconfig.lib.json'),
pathsToAliases: false,
}),
],

Expand Down
1 change: 1 addition & 0 deletions packages/php-wasm/progress/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default defineConfig({
dts({
entryRoot: 'src',
tsconfigPath: join(__dirname, 'tsconfig.lib.json'),
pathsToAliases: false,
}),

viteTsConfigPaths({
Expand Down
1 change: 1 addition & 0 deletions packages/php-wasm/scopes/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default defineConfig({
dts({
entryRoot: 'src',
tsconfigPath: join(__dirname, 'tsconfig.lib.json'),
pathsToAliases: false,
}),

viteTsConfigPaths({
Expand Down
1 change: 1 addition & 0 deletions packages/php-wasm/stream-compression/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default defineConfig({
dts({
entryRoot: 'src',
tsconfigPath: path.join(__dirname, 'tsconfig.lib.json'),
pathsToAliases: false,
}),
viteTsConfigPaths({
root: '../../../',
Expand Down
1 change: 1 addition & 0 deletions packages/php-wasm/universal/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default defineConfig({
dts({
entryRoot: 'src',
tsconfigPath: join(__dirname, 'tsconfig.lib.json'),
pathsToAliases: false,
}),

viteTsConfigPaths({
Expand Down
1 change: 1 addition & 0 deletions packages/php-wasm/util/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default defineConfig({
dts({
entryRoot: 'src',
tsconfigPath: join(__dirname, 'tsconfig.lib.json'),
pathsToAliases: false,
}),

viteTsConfigPaths({
Expand Down
1 change: 1 addition & 0 deletions packages/php-wasm/web-service-worker/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default defineConfig({
dts({
entryRoot: 'src',
tsconfigPath: join(__dirname, 'tsconfig.lib.json'),
pathsToAliases: false,
}),

viteTsConfigPaths({
Expand Down
1 change: 1 addition & 0 deletions packages/php-wasm/web/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default defineConfig(({ command }) => {
dts({
entryRoot: 'src',
tsconfigPath: join(__dirname, 'tsconfig.lib.json'),
pathsToAliases: false,
}),
{
name: 'ignore-wasm-imports',
Expand Down
1 change: 1 addition & 0 deletions packages/playground/blueprints/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default defineConfig({
dts({
entryRoot: 'src',
tsconfigPath: join(__dirname, 'tsconfig.lib.json'),
pathsToAliases: false,
}),

viteTsConfigPaths({
Expand Down
1 change: 1 addition & 0 deletions packages/playground/client/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default defineConfig({
dts({
entryRoot: 'src',
tsconfigPath: join(__dirname, 'tsconfig.lib.json'),
pathsToAliases: false,
}),
ignoreWasmImports(),

Expand Down
1 change: 1 addition & 0 deletions packages/playground/common/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default defineConfig({
dts({
entryRoot: 'src',
tsconfigPath: path('tsconfig.lib.json'),
pathsToAliases: false,
}),
],

Expand Down
1 change: 1 addition & 0 deletions packages/playground/remote/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const plugins = [
dts({
entryRoot: 'src',
tsconfigPath: join(__dirname, 'tsconfig.lib.json'),
pathsToAliases: false,
}),
/**
* Copy the `.htaccess` file to the `dist` directory.
Expand Down
1 change: 1 addition & 0 deletions packages/playground/wordpress-builds/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default defineConfig({
dts({
entryRoot: 'src',
tsconfigPath: path('tsconfig.lib.json'),
pathsToAliases: false,
}),
{
name: 'use-correct-wp-data-file-url-in-vitest-environment',
Expand Down
1 change: 1 addition & 0 deletions packages/playground/wordpress/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default defineConfig({
dts({
entryRoot: 'src',
tsconfigPath: path('tsconfig.lib.json'),
pathsToAliases: false,
}),
{
name: 'use-correct-wp-data-file-url-in-vitest-environment',
Expand Down

0 comments on commit 2461532

Please sign in to comment.