Skip to content

Commit

Permalink
Update rollup config (#66)
Browse files Browse the repository at this point in the history
* build: simplify rollup.config.mjs
* fix: circular dependency
* build: update rollup version
  • Loading branch information
xiaoxiangmoe committed Aug 30, 2023
1 parent baf9953 commit 852c3cb
Show file tree
Hide file tree
Showing 6 changed files with 832 additions and 754 deletions.
6 changes: 3 additions & 3 deletions packages/model/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@
"jsdom": "^22.1.0",
"node-fetch": "^3.3.1",
"prettier": "^2.8.8",
"rollup": "3.21.7",
"rollup-plugin-dts": "5.3.0",
"rollup-plugin-typescript2": "^0.34.1",
"rollup": "3.28.1",
"rollup-plugin-dts": "6.0.0",
"rollup-plugin-typescript2": "^0.35.0",
"rxjs": "^7.8.1",
"ts-node": "^10.9.1",
"tslib": "^2.5.2",
Expand Down
56 changes: 25 additions & 31 deletions packages/model/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,53 +3,47 @@ import dts from 'rollup-plugin-dts';
import * as fs from 'node:fs';
import ts from 'rollup-plugin-typescript2';

/**
* @type {{
* peerDependencies: Record<string, string>;
* dependencies: Record<string, string>;
* exports: { ".": { "import": string, "require": string }}
* }}
*/
/** @type {import('./package.json')} */
const { peerDependencies, dependencies, exports } = JSON.parse(
fs.readFileSync('./package.json', { encoding: 'utf-8' }),
);

const external = [...Object.keys(peerDependencies ?? {}), ...Object.keys(dependencies ?? {})];

/** @type { import('rollup').RollupOptions } */
const dtsConfig = {
plugins: [
dts({
respectExternal: true,
tsconfig: './tsconfig.lib.json',
compilerOptions: {
// see https://github.com/unjs/unbuild/pull/57/files
preserveSymlinks: false,
},
}),
],
external,
input: './src/index.ts',
};

/** @type { Array<import('rollup').RollupOptions> } */
const config = [
{
plugins: [ts()],
external,
input: './src/index.ts',
output: [
{ file: exports['.'].require, format: 'cjs' },
{ file: exports['.'].import, format: 'es' },
{
file: exports['.'].require,
format: 'cjs',
},
{
file: exports['.'].import,
format: 'es',
},
],
},
{
...dtsConfig,
output: [{ file: exports['.'].require.replace('.cjs', '.d.cts'), format: 'es' }],
},
{
...dtsConfig,
output: [{ file: exports['.'].import.replace('.mjs', '.d.mts'), format: 'es' }],
plugins: [
dts({
respectExternal: true,
tsconfig: './tsconfig.lib.json',
compilerOptions: {
// see https://github.com/unjs/unbuild/pull/57/files
preserveSymlinks: false,
},
}),
],
external,
input: './src/index.ts',
output: [
{ file: exports['.'].require.replace('.cjs', '.d.cts') },
{ file: exports['.'].import.replace('.mjs', '.d.mts') },
],
},
];

Expand Down
4 changes: 1 addition & 3 deletions packages/model/src/operations/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ import { fromWatch } from '../utils';
import { Observable, merge, map } from 'rxjs';
import { MODE } from '../const';

export function isDef<T>(v: T): v is NonNullable<T> {
return v !== undefined && v !== null;
}
export { isDef } from '../utils';

export function initDataType<DataType>() {
const data: InfoDataType<DataType> = {
Expand Down
2 changes: 1 addition & 1 deletion packages/model/src/operations/status.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { ComputedRef, Ref } from 'vue-demi';

import { computed } from 'vue-demi';
import { isDef } from './core';
import { isDef } from '../utils';

export interface InfoDataType<T> {
data: T | undefined;
Expand Down
4 changes: 4 additions & 0 deletions packages/model/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,7 @@ export function fromWatch<T>(fn: WatchSource<T>, watchOptions?: WatchOptions) {
}, watchOptions);
});
}

export function isDef<T>(v: T): v is NonNullable<T> {
return v !== undefined && v !== null;
}
Loading

0 comments on commit 852c3cb

Please sign in to comment.