Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .config/tsconfig.base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"lib": ["ESNext"],
"module": "esnext",
"moduleResolution": "bundler",
"noEmit": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"pretty": true,
"sourceMap": true,
"strict": true,
"target": "ES2022"
},
"exclude": ["dist", "node_modules", "test/types"]
}
13 changes: 13 additions & 0 deletions .config/tsconfig.plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
// Important: this config is symlinked into package directories as `tsconfig.json`.
// The `extends` path must therefore be relative to the symlink location (e.g. packages/<pkg>/).
"extends": "../../.config/tsconfig.base.json",
"compilerOptions": {
"noEmit": false,
"outDir": "dist",
"rootDir": "src",
"declaration": true,
"declarationMap": true
},
"include": ["src/**/*"]
}
14 changes: 14 additions & 0 deletions .config/vitest.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { defineConfig } from 'vitest/config';
import path from 'node:path';

export default defineConfig({
test: {
// Store snapshots next to each test in a .snapshots folder
resolveSnapshotPath: (testPath, snapExt) =>
path.join(path.dirname(testPath), '.snapshots', path.basename(testPath) + snapExt)
},
resolve: {
// Allow importing the current package under test via `~package`
alias: [{ find: /^~package$/, replacement: path.resolve(process.cwd()) }]
}
});
Comment thread
shellscape marked this conversation as resolved.
14 changes: 14 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ Any code change should be submitted as a pull request. Our guidelines for Pull R
- Before submitting your Pull Request, please lint your changes by running `pnpm lint` in the root directory
- 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

## Testing packages

Some packages use Vitest for tests. When converting or running tests locally inside a package directory (e.g. `packages/alias`):

- Tests import the package under test via `~package`. A shared config at `.config/vitest.config.mts` provides a runtime alias that resolves `~package` to the current working directory.
- Snapshots are written alongside each test under a local `.snapshots` directory.

Example (from a package directory):

```
pnpm build
pnpm test
```

## Code review process

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.
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"devDependencies": {
"@dot/versioner": "^0.3.1",
"@rollup/plugin-typescript": "^9.0.1",
"@types/node": "14.18.30",
"@types/node": "^20.19.0",
"@types/source-map-support": "^0.5.4",
"@typescript-eslint/eslint-plugin": "^5.38.0",
"@typescript-eslint/parser": "^5.38.0",
Expand All @@ -39,7 +39,8 @@
"prettier-plugin-package": "^1.3.0",
"source-map-support": "^0.5.21",
"ts-node": "10.9.1",
"typescript": "^4.8.3"
"typescript": "^5.9.3",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CharlieHelps the root package.json should have the catalog use as well

@charliecreates charliecreates Bot Oct 28, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expand this to see my work.
  • Confirmed catalog usage in pnpm-workspace.yaml (e.g., catalog.typescript: ^5.9.3) and found root package.json pins devDependencies.typescript to ^5.9.3 while packages/alias/package.json uses "typescript": "catalog:" — so the root should adopt catalog:.
  • Built and tested packages/alias: TypeScript build succeeded (tsc --project tsconfig.json), and tests passed 20/20 via vitest (../../.config/vitest.config.mts).
  • Noted a non-blocking warning about a missing base config referenced by ../../.config/tsconfig.plugin.json in relation to packages/alias/tsconfig.json; build and tests still succeed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done—root now uses the pnpm catalog for TypeScript.

  • package.json: set "typescript": "catalog:" to align with the workspace catalog in pnpm-workspace.yaml
  • pnpm-lock.yaml refreshed by install
  • packageManager is already pnpm@9.5.0

Change: c243716

Verification
# Update deps/lockfile (catalog resolves typescript to ^5.9.3)
$ pnpm install
# Result: workspace install OK; typescript -> 5.9.3 (from catalog)

# Build alias (sanity check)
$ pnpm -C packages/alias build
# Result: tsc success

# Run alias tests (Vitest, ESM config)
$ pnpm -C packages/alias test
# Result: 1 file, 20 tests — all passed

Self review notes:

  • “Enforce pnpm v9+” warning skipped: packageManager already set to pnpm@9.5.0 at repo root.
  • Kept shorthand "catalog:" (instead of "catalog:typescript") to match usage in packages/alias and the workspace comment in pnpm-workspace.yaml.

"vitest": "^4.0.2"
},
"ava": {
"files": [
Expand Down Expand Up @@ -77,5 +78,5 @@
"test/"
]
},
"packageManager": "pnpm@9.4.0"
"packageManager": "pnpm@9.5.0"
}
36 changes: 11 additions & 25 deletions packages/alias/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,30 @@
"author": "Johannes Stein",
"homepage": "https://github.com/rollup/plugins/tree/master/packages/alias#readme",
"bugs": "https://github.com/rollup/plugins/issues",
"main": "./dist/cjs/index.js",
"module": "./dist/es/index.js",
"type": "module",
"exports": {
"types": "./types/index.d.ts",
"import": "./dist/es/index.js",
"default": "./dist/cjs/index.js"
"types": "./dist/index.d.ts",
"import": "./dist/index.js"
},
"engines": {
"node": ">=14.0.0"
"node": ">=20.19.0"
},
"scripts": {
"build": "rollup -c",
"build": "tsc --project tsconfig.json",
"ci:coverage": "nyc pnpm test && nyc report --reporter=text-lcov > coverage.lcov",
"ci:lint": "pnpm build && pnpm lint",
"ci:lint:commits": "commitlint --from=${CIRCLE_BRANCH} --to=${CIRCLE_SHA1}",
"ci:test": "pnpm test -- --verbose",
"ci:test": "pnpm test -- --reporter=verbose",
"prebuild": "del-cli dist",
"prepare": "if [ ! -d 'dist' ]; then pnpm build; fi",
"prerelease": "pnpm build",
"pretest": "pnpm build",
"release": "pnpm --workspace-root package:release $(pwd)",
"test": "ava",
"test:ts": "tsc --noEmit"
"test": "vitest --config ../../.config/vitest.config.mts run"
},
"files": [
"dist",
"!dist/**/*.map",
"types",
"README.md",
"LICENSE"
],
Expand All @@ -51,7 +47,7 @@
"alias"
],
"peerDependencies": {
"rollup": "^1.20.0||^2.0.0||^3.0.0||^4.0.0"
"rollup": ">=4.0.0"
},
"peerDependenciesMeta": {
"rollup": {
Expand All @@ -60,19 +56,9 @@
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^15.0.0",
"@rollup/plugin-typescript": "^9.0.1",
"del-cli": "^5.0.0",
"rollup": "^4.0.0-24",
"typescript": "^4.8.3"
"rollup": "^4.0.0",
"typescript": "catalog:"
},
"types": "./types/index.d.ts",
"ava": {
"files": [
"!**/fixtures/**",
"!**/output/**",
"!**/helpers/**",
"!**/recipes/**",
"!**/types.ts"
]
}
"types": "./dist/index.d.ts"
}
7 changes: 0 additions & 7 deletions packages/alias/rollup.config.mjs

This file was deleted.

48 changes: 43 additions & 5 deletions packages/alias/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,46 @@
import path from 'path';
import path from 'node:path';

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

import type { ResolvedAlias, ResolverFunction, ResolverObject, RollupAliasOptions } from '../types';
// Narrow to explicit callable form instead of the global `Function` type.
type MapToFunction<T> = T extends (...args: any[]) => any ? T : never;

export type ResolverFunction = MapToFunction<PluginHooks['resolveId']>;

export interface ResolverObject {
buildStart?: PluginHooks['buildStart'];
resolveId: ResolverFunction;
}

export interface Alias {
find: string | RegExp;
replacement: string;
customResolver?: ResolverFunction | ResolverObject | null;
}

export interface ResolvedAlias {
find: string | RegExp;
replacement: string;
resolverFunction: ResolverFunction | null;
}

export interface RollupAliasOptions {
/**
* Instructs the plugin to use an alternative resolving algorithm,
* rather than the Rollup's resolver.
* @default null
*/
customResolver?: ResolverFunction | ResolverObject | null;

/**
* Specifies an `Object`, or an `Array` of `Object`,
* which defines aliases used to replace values in `import` or `require` statements.
* With either format, the order of the entries is important,
* in that the first defined rules are applied first.
*/
entries?: readonly Alias[] | { [find: string]: string };
}

function matches(pattern: string | RegExp, importee: string) {
if (pattern instanceof RegExp) {
Expand Down Expand Up @@ -40,7 +78,7 @@ function getEntries({ entries, customResolver }: RollupAliasOptions): readonly R
});
}

function getHookFunction<T extends Function>(hook: T | { handler?: T }): T | null {
function getHookFunction<T extends (...args: any[]) => any>(hook: T | { handler?: T }): T | null {
if (typeof hook === 'function') {
return hook;
}
Expand Down Expand Up @@ -104,7 +142,7 @@ export default function alias(options: RollupAliasOptions = {}): Plugin {

if (!path.isAbsolute(updatedId)) {
this.warn(
`rewrote ${importee} to ${updatedId} but was not an abolute path and was not handled by other plugins. ` +
`rewrote ${importee} to ${updatedId} but was not an absolute path and was not handled by other plugins. ` +
`This will lead to duplicated modules for the same path. ` +
`To avoid duplicating modules, you should resolve to an absolute path.`
);
Expand Down
Loading
Loading