Skip to content

Commit 26bb927

Browse files
committed
feat(alias)!: ESM only; tsc-only build; Node >=20.19.0 and Rollup >=4\n\n- Convert @rollup/plugin-alias to ESM-only with "type": "module" and exports { import, types } to dist\n- Drop Rollup from package build; build with tsc to dist (JS, d.ts, and maps)\n- Raise engines.node to >=20.19.0 and peer rollup to >=4.0.0; keep dev rollup for tests\n- Inline and export public types from src; remove hand-authored types/\n- Add shared .config/{tsconfig.base.json,tsconfig.plugin.json,vitest.config.ts}\n- Switch tests to Vitest (TypeScript), import from ~package, drop CJS branch\n- Update CONTRIBUTING: Vitest + ~package alias + snapshots\n- Bump workspace TypeScript and @types/node; install Vitest at the root
1 parent 973054d commit 26bb927

File tree

14 files changed

+1590
-839
lines changed

14 files changed

+1590
-839
lines changed

.config/tsconfig.base.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"compilerOptions": {
3+
"allowSyntheticDefaultImports": true,
4+
"esModuleInterop": true,
5+
"lib": ["ESNext"],
6+
"module": "esnext",
7+
"moduleResolution": "bundler",
8+
"noEmit": true,
9+
"noUnusedLocals": true,
10+
"noUnusedParameters": true,
11+
"pretty": true,
12+
"sourceMap": true,
13+
"strict": true,
14+
"target": "ES2022"
15+
},
16+
"exclude": ["dist", "node_modules", "test/types"]
17+
}

.config/tsconfig.plugin.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"extends": "../../.config/tsconfig.base.json",
3+
"compilerOptions": {
4+
"noEmit": false,
5+
"outDir": "dist",
6+
"rootDir": "src",
7+
"declaration": true,
8+
"declarationMap": true,
9+
"sourceMap": true,
10+
"baseUrl": ".",
11+
"paths": { "~package": ["./"] }
12+
},
13+
"include": ["src/**/*"]
14+
}

.config/vitest.config.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { defineConfig } from 'vitest/config';
2+
import path from 'node:path';
3+
4+
export default defineConfig({
5+
test: {
6+
// Store snapshots next to each test in a .snapshots folder
7+
resolveSnapshotPath: (testPath, snapExt) =>
8+
path.join(path.dirname(testPath), '.snapshots', path.basename(testPath) + snapExt)
9+
},
10+
resolve: {
11+
// Allow importing the current package under test via `~package`
12+
alias: [{ find: /^~package$/, replacement: path.resolve(process.cwd()) }]
13+
}
14+
});

.github/CONTRIBUTING.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@ Any code change should be submitted as a pull request. Our guidelines for Pull R
2626
- Before submitting your Pull Request, please lint your changes by running `pnpm lint` in the root directory
2727
- If any checks fail for your Pull Request, please resolve them. Always feel free to ask for help if unable to resolve issues with checks
2828

29+
## Testing packages
30+
31+
Some packages use Vitest for tests. When converting or running tests locally inside a package directory (e.g. `packages/alias`):
32+
33+
- Tests import the package under test via `~package`. A shared config at `.config/vitest.config.ts` provides a runtime alias that resolves `~package` to the current working directory.
34+
- Snapshots are written alongside each test under a local `.snapshots` directory.
35+
36+
Example (from a package directory):
37+
38+
```
39+
pnpm build
40+
pnpm test
41+
```
42+
2943
## Code review process
3044

3145
The bigger the pull request, the longer it will take to review and merge. Try to break down large pull requests in smaller chunks that are easier to review and merge.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"devDependencies": {
2020
"@dot/versioner": "^0.3.1",
2121
"@rollup/plugin-typescript": "^9.0.1",
22-
"@types/node": "14.18.30",
22+
"@types/node": "^20.19.0",
2323
"@types/source-map-support": "^0.5.4",
2424
"@typescript-eslint/eslint-plugin": "^5.38.0",
2525
"@typescript-eslint/parser": "^5.38.0",
@@ -38,7 +38,8 @@
3838
"prettier-plugin-package": "^1.3.0",
3939
"source-map-support": "^0.5.21",
4040
"ts-node": "10.9.1",
41-
"typescript": "^4.8.3"
41+
"typescript": "^5.9.3",
42+
"vitest": "^4.0.2"
4243
},
4344
"ava": {
4445
"files": [

packages/alias/package.json

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,16 @@
1313
"author": "Johannes Stein",
1414
"homepage": "https://github.com/rollup/plugins/tree/master/packages/alias#readme",
1515
"bugs": "https://github.com/rollup/plugins/issues",
16-
"main": "./dist/cjs/index.js",
17-
"module": "./dist/es/index.js",
16+
"type": "module",
1817
"exports": {
19-
"types": "./types/index.d.ts",
20-
"import": "./dist/es/index.js",
21-
"default": "./dist/cjs/index.js"
18+
"types": "./dist/index.d.ts",
19+
"import": "./dist/index.js"
2220
},
2321
"engines": {
24-
"node": ">=14.0.0"
22+
"node": ">=20.19.0"
2523
},
2624
"scripts": {
27-
"build": "rollup -c",
25+
"build": "tsc --project tsconfig.json",
2826
"ci:coverage": "nyc pnpm test && nyc report --reporter=text-lcov > coverage.lcov",
2927
"ci:lint": "pnpm build && pnpm lint",
3028
"ci:lint:commits": "commitlint --from=${CIRCLE_BRANCH} --to=${CIRCLE_SHA1}",
@@ -34,13 +32,10 @@
3432
"prerelease": "pnpm build",
3533
"pretest": "pnpm build",
3634
"release": "pnpm --workspace-root package:release $(pwd)",
37-
"test": "ava",
38-
"test:ts": "tsc --noEmit"
35+
"test": "vitest --config ../../.config/vitest.config.ts run"
3936
},
4037
"files": [
4138
"dist",
42-
"!dist/**/*.map",
43-
"types",
4439
"README.md",
4540
"LICENSE"
4641
],
@@ -51,7 +46,7 @@
5146
"alias"
5247
],
5348
"peerDependencies": {
54-
"rollup": "^1.20.0||^2.0.0||^3.0.0||^4.0.0"
49+
"rollup": ">=4.0.0"
5550
},
5651
"peerDependenciesMeta": {
5752
"rollup": {
@@ -60,19 +55,9 @@
6055
},
6156
"devDependencies": {
6257
"@rollup/plugin-node-resolve": "^15.0.0",
63-
"@rollup/plugin-typescript": "^9.0.1",
6458
"del-cli": "^5.0.0",
65-
"rollup": "^4.0.0-24",
66-
"typescript": "^4.8.3"
59+
"rollup": "^4.0.0",
60+
"typescript": "^5.6.3"
6761
},
68-
"types": "./types/index.d.ts",
69-
"ava": {
70-
"files": [
71-
"!**/fixtures/**",
72-
"!**/output/**",
73-
"!**/helpers/**",
74-
"!**/recipes/**",
75-
"!**/types.ts"
76-
]
77-
}
62+
"types": "./dist/index.d.ts"
7863
}

packages/alias/rollup.config.mjs

Lines changed: 0 additions & 7 deletions
This file was deleted.

packages/alias/src/index.ts

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,45 @@
1-
import path from 'path';
1+
import path from 'node:path';
22

3-
import type { Plugin } from 'rollup';
3+
// Public types are exported directly from source so tsc can emit declarations
4+
import type { Plugin, PluginHooks } from 'rollup';
45

5-
import type { ResolvedAlias, ResolverFunction, ResolverObject, RollupAliasOptions } from '../types';
6+
type MapToFunction<T> = T extends Function ? T : never;
7+
8+
export type ResolverFunction = MapToFunction<PluginHooks['resolveId']>;
9+
10+
export interface ResolverObject {
11+
buildStart?: PluginHooks['buildStart'];
12+
resolveId: ResolverFunction;
13+
}
14+
15+
export interface Alias {
16+
find: string | RegExp;
17+
replacement: string;
18+
customResolver?: ResolverFunction | ResolverObject | null;
19+
}
20+
21+
export interface ResolvedAlias {
22+
find: string | RegExp;
23+
replacement: string;
24+
resolverFunction: ResolverFunction | null;
25+
}
26+
27+
export interface RollupAliasOptions {
28+
/**
29+
* Instructs the plugin to use an alternative resolving algorithm,
30+
* rather than the Rollup's resolver.
31+
* @default null
32+
*/
33+
customResolver?: ResolverFunction | ResolverObject | null;
34+
35+
/**
36+
* Specifies an `Object`, or an `Array` of `Object`,
37+
* which defines aliases used to replace values in `import` or `require` statements.
38+
* With either format, the order of the entries is important,
39+
* in that the first defined rules are applied first.
40+
*/
41+
entries?: readonly Alias[] | { [find: string]: string };
42+
}
643

744
function matches(pattern: string | RegExp, importee: string) {
845
if (pattern instanceof RegExp) {

0 commit comments

Comments
 (0)