From f9124aa6b5d87937df35db88d4ba5563a1c89fe6 Mon Sep 17 00:00:00 2001 From: ambar Date: Sun, 12 Sep 2021 15:16:00 +0800 Subject: [PATCH] chore: use rollup-plugin-typescript2 --- package.json | 10 +-- packages/griffith-hls/package.json | 3 +- packages/griffith-message/package.json | 3 +- packages/griffith-mp4/package.json | 3 +- packages/griffith-standalone/package.json | 1 - packages/griffith-utils/package.json | 3 +- packages/griffith/package.json | 3 +- rollup.config.js | 29 +++--- tsconfig.build.json | 7 -- tsconfig.json | 103 ++-------------------- yarn.lock | 36 +++++++- 11 files changed, 71 insertions(+), 130 deletions(-) delete mode 100644 tsconfig.build.json diff --git a/package.json b/package.json index 7c1700c1..cd1aba4e 100644 --- a/package.json +++ b/package.json @@ -32,16 +32,14 @@ "zhihu-video-player" ], "scripts": { - "format": "prettier --check \"packages/**/*.{js,json,md}\" \"*.{js,json,md}\"", - "format:fix": "prettier --write \"packages/**/*.{js,json,md}\" \"*.{js,json,md}\"", - "lint": "eslint 'packages/*/src/**/*.js' '*.js'", + "lint": "eslint .", "test": "jest", "test:coverage": "jest --coverage", "test:watch": "jest --watch --notify", - "build:lib": "lerna run build --ignore example --ignore website", + "build:lib": "lerna run build --scope griffith* --parallel", "deploy:website": "lerna run --scope website deploy", "build": "yarn build:lib", - "build:watch": "lerna run build --parallel --ignore example --ignore website --ignore griffith-standalone -- --watch", + "build:watch": "lerna run build --parallel --scope griffith* --ignore griffith-standalone -- --watch", "release": "yarn build && lerna publish", "start-server": "yarn workspace example run start", "start": "yarn start-server" @@ -57,6 +55,7 @@ "@rollup/plugin-commonjs": "^19.0.0", "@rollup/plugin-node-resolve": "^13.0.0", "@rollup/plugin-replace": "^2.4.2", + "@rollup/plugin-typescript": "^8.2.5", "@types/enzyme": "^3.10.9", "@types/jest": "^27.0.1", "@typescript-eslint/eslint-plugin": "^4.31.0", @@ -81,6 +80,7 @@ "prettier": "^2.3.2", "rollup": "^2.48.0", "rollup-plugin-terser": "^7.0.2", + "rollup-plugin-typescript2": "^0.30.0", "ts-migrate": "^0.1.22" }, "husky": { diff --git a/packages/griffith-hls/package.json b/packages/griffith-hls/package.json index 9bbb0e03..09f0635d 100644 --- a/packages/griffith-hls/package.json +++ b/packages/griffith-hls/package.json @@ -12,10 +12,9 @@ "module": "dist/index.esm.js", "types": "dist/index.d.ts", "sideEffects": false, - "browserslist": ["maintained node versions"], "scripts": { "prebuild": "rm -rf dist/**", - "build": "microbundle --tsconfig ../../tsconfig.build.json -f cjs,esm --no-sourcemap --no-compress --jsx React.createElement" + "build": "rollup -c ../../rollup.config.js" }, "peerDependencies": { "react": "^16.8 || ^17", diff --git a/packages/griffith-message/package.json b/packages/griffith-message/package.json index 560f1dcd..c296552c 100644 --- a/packages/griffith-message/package.json +++ b/packages/griffith-message/package.json @@ -12,9 +12,8 @@ "module": "dist/index.esm.js", "types": "dist/index.d.ts", "sideEffects": false, - "browserslist": ["maintained node versions"], "scripts": { "prebuild": "rm -rf dist/**", - "build": "microbundle --tsconfig ../../tsconfig.build.json -f cjs,esm --no-sourcemap --no-compress" + "build": "rollup -c ../../rollup.config.js" } } diff --git a/packages/griffith-mp4/package.json b/packages/griffith-mp4/package.json index cb4e2f62..db83f9f6 100644 --- a/packages/griffith-mp4/package.json +++ b/packages/griffith-mp4/package.json @@ -12,10 +12,9 @@ "module": "dist/index.esm.js", "types": "dist/index.d.ts", "sideEffects": false, - "browserslist": ["maintained node versions"], "scripts": { "prebuild": "rm -rf dist/**", - "build": "microbundle --tsconfig ../../tsconfig.build.json -f cjs,esm --no-sourcemap --no-compress --jsx React.createElement" + "build": "rollup -c ../../rollup.config.js" }, "devDependencies": { "read-chunk": "^3.0.0" diff --git a/packages/griffith-standalone/package.json b/packages/griffith-standalone/package.json index 1220e69e..cbf7e1ce 100644 --- a/packages/griffith-standalone/package.json +++ b/packages/griffith-standalone/package.json @@ -14,7 +14,6 @@ "build": "rollup -c" }, "devDependencies": { - "babel-loader": "^8.0.5", "griffith": "^1.17.0", "react": "^16.8", "react-dom": "^16.8" diff --git a/packages/griffith-utils/package.json b/packages/griffith-utils/package.json index 01185f0c..f945c52f 100644 --- a/packages/griffith-utils/package.json +++ b/packages/griffith-utils/package.json @@ -12,9 +12,8 @@ "module": "dist/index.esm.js", "types": "dist/index.d.ts", "sideEffects": false, - "browserslist": ["maintained node versions"], "scripts": { "prebuild": "rm -rf dist/**", - "build": "microbundle --tsconfig ../../tsconfig.build.json -f cjs,esm --no-sourcemap --no-compress" + "build": "rollup -c ../../rollup.config.js" } } diff --git a/packages/griffith/package.json b/packages/griffith/package.json index c1d7f29d..d1b137aa 100644 --- a/packages/griffith/package.json +++ b/packages/griffith/package.json @@ -13,10 +13,9 @@ "module": "dist/index.esm.js", "types": "dist/index.d.ts", "sideEffects": false, - "browserslist": ["maintained node versions"], "scripts": { "prebuild": "rm -rf dist/**", - "build": "microbundle --tsconfig ../../tsconfig.build.json -f cjs,esm --no-sourcemap --no-compress --jsx React.createElement" + "build": "rollup -c ../../rollup.config.js" }, "peerDependencies": { "react": "^16.8 || ^17", diff --git a/rollup.config.js b/rollup.config.js index 362f42a2..4e3b2ed4 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,9 +1,9 @@ import path from 'path' -import babel from '@rollup/plugin-babel' -import resolve from '@rollup/plugin-node-resolve' - -const pkg = require(path.resolve(process.cwd(), 'package.json')) +import typescript from 'rollup-plugin-typescript2' +import findCacheDir from 'find-cache-dir' +const resolveCwd = path.resolve.bind(null, process.cwd()) +const pkg = require(resolveCwd('package.json')) const deps = Object.keys({...pkg.dependencies, ...pkg.peerDependencies}) const reExternal = new RegExp(`^(${deps.join('|')})($|/)`) @@ -14,19 +14,28 @@ export default [ { file: pkg.main, format: 'cjs', - sourcemap: true, }, { file: pkg.module, format: 'esm', - sourcemap: true, }, ], plugins: [ - babel(require('./babel.config')), - // resolves `./directory` to `./directory/index.js` - resolve({only: [/\/packages\/.*/]}), + typescript({ + cacheRoot: findCacheDir({ + name: 'rollup-plugin-typescript2', + cwd: __dirname, + }), + tsconfigOverride: { + include: [resolveCwd('src/**/*')], + exclude: ['**/*.spec.*', '**/__tests__'], + compilerOptions: { + // reset to empty + paths: {}, + }, + }, + }), ], - external: id => (deps.length ? reExternal.test(id) : false), + external: (id) => (deps.length ? reExternal.test(id) : false), }, ] diff --git a/tsconfig.build.json b/tsconfig.build.json deleted file mode 100644 index 81fe789d..00000000 --- a/tsconfig.build.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - // reset to empty - "paths": {} - } -} diff --git a/tsconfig.json b/tsconfig.json index 73a9a0c4..d3cee817 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,35 +1,9 @@ { "compilerOptions": { /* Visit https://aka.ms/tsconfig.json to read more about this file */ - - /* Projects */ - // "incremental": true, /* Enable incremental compilation */ - // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ - // "tsBuildInfoFile": "./", /* Specify the folder for .tsbuildinfo incremental compilation files. */ - // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects */ - // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ - // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ - - /* Language and Environment */ - "target": "ESNext" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */, - // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ - /* Specify what JSX code is generated. */ + "target": "ES6", "jsx": "react", - // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */ - // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ - // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h' */ - // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ - // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using `jsx: react-jsx*`.` */ - // "reactNamespace": "", /* Specify the object invoked for `createElement`. This only applies when targeting `react` JSX emit. */ - // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ - // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ - - /* Modules */ - "module": "commonjs" /* Specify what module code is generated. */, - // "rootDir": "./", /* Specify the root folder within your source files. */ - // "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ - // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ - /* Specify a set of entries that re-map imports to additional lookup locations. */ + "module": "ESNext", "paths": { // link all packages without build step "griffith-mp4": ["./packages/griffith-mp4/src/index.ts"], @@ -38,72 +12,11 @@ "griffith-message": ["./packages/griffith-message/src/index.ts"], "griffith": ["./packages/griffith/src/index.ts"] }, - // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ - // "typeRoots": [], /* Specify multiple folders that act like `./node_modules/@types`. */ - // "types": [], /* Specify type package names to be included without being referenced in a source file. */ - // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ - // "resolveJsonModule": true, /* Enable importing .json files */ - // "noResolve": true, /* Disallow `import`s, `require`s or ``s from expanding the number of files TypeScript should add to a project. */ - - /* JavaScript Support */ - // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */ - // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ - // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from `node_modules`. Only applicable with `allowJs`. */ - - /* Emit */ - // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ - // "declarationMap": true, /* Create sourcemaps for d.ts files. */ - // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ - // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ - // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */ - // "outDir": "./", /* Specify an output folder for all emitted files. */ - // "removeComments": true, /* Disable emitting comments. */ - // "noEmit": true, /* Disable emitting files from a compilation. */ - // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ - // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types */ - // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ - // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ - // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ - // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ - // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ - // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ - // "newLine": "crlf", /* Set the newline character for emitting files. */ - // "stripInternal": true, /* Disable emitting declarations that have `@internal` in their JSDoc comments. */ - // "noEmitHelpers": true, /* Disable generating custom helper functions like `__extends` in compiled output. */ - // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ - // "preserveConstEnums": true, /* Disable erasing `const enum` declarations in generated code. */ - // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ - - /* Interop Constraints */ - // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ - // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ - "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */, - // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ - "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */, - - /* Type Checking */ - "strict": true /* Enable all strict type-checking options. */, - // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied `any` type.. */ - // "strictNullChecks": true, /* When type checking, take into account `null` and `undefined`. */ - // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ - // "strictBindCallApply": true, /* Check that the arguments for `bind`, `call`, and `apply` methods match the original function. */ - // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ - // "noImplicitThis": true, /* Enable error reporting when `this` is given the type `any`. */ - // "useUnknownInCatchVariables": true, /* Type catch clause variables as 'unknown' instead of 'any'. */ - // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ - // "noUnusedLocals": true, /* Enable error reporting when a local variables aren't read. */ - // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read */ - // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ - // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ - // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ - // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ - // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ - // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type */ - // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ - // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ - - /* Completeness */ - // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ - "skipLibCheck": true /* Skip type checking all .d.ts files. */ + "declaration": true, + // import @types/react + "allowSyntheticDefaultImports": true, + "forceConsistentCasingInFileNames": true, + "strict": true, + "skipLibCheck": true } } diff --git a/yarn.lock b/yarn.lock index e8b74eb1..79711482 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2233,6 +2233,14 @@ "@rollup/pluginutils" "^3.1.0" magic-string "^0.25.7" +"@rollup/plugin-typescript@^8.2.5": + version "8.2.5" + resolved "https://registry.yarnpkg.com/@rollup/plugin-typescript/-/plugin-typescript-8.2.5.tgz#e0319761b2b5105615e5a0c371ae05bc2984b7de" + integrity sha512-QL/LvDol/PAGB2O0S7/+q2HpSUNodpw7z6nGn9BfoVCPOZ0r4EALrojFU29Bkoi2Hr2jgTocTejJ5GGWZfOxbQ== + dependencies: + "@rollup/pluginutils" "^3.1.0" + resolve "^1.17.0" + "@rollup/pluginutils@^3.0.8", "@rollup/pluginutils@^3.1.0": version "3.1.0" resolved "https://registry.yarnpkg.com/@rollup/pluginutils/-/pluginutils-3.1.0.tgz#706b4524ee6dc8b103b3c995533e5ad680c02b9b" @@ -2242,6 +2250,14 @@ estree-walker "^1.0.1" picomatch "^2.2.2" +"@rollup/pluginutils@^4.1.0": + version "4.1.1" + resolved "https://registry.yarnpkg.com/@rollup/pluginutils/-/pluginutils-4.1.1.tgz#1d4da86dd4eded15656a57d933fda2b9a08d47ec" + integrity sha512-clDjivHqWGXi7u+0d2r2sBi4Ie6VLEAzWMIkvJLnDmxoOhBYOTfzGbOQBA32THHm11/LiJbd01tJUpJsbshSWQ== + dependencies: + estree-walker "^2.0.1" + picomatch "^2.2.2" + "@samverschueren/stream-to-observable@^0.3.0": version "0.3.0" resolved "https://registry.yarnpkg.com/@samverschueren/stream-to-observable/-/stream-to-observable-0.3.0.tgz#ecdf48d532c58ea477acfcab80348424f8d0662f" @@ -3365,7 +3381,7 @@ babel-jest@^27.1.0: graceful-fs "^4.2.4" slash "^3.0.0" -babel-loader@^8.0.0, babel-loader@^8.0.5: +babel-loader@^8.0.0: version "8.0.5" resolved "https://registry.yarnpkg.com/babel-loader/-/babel-loader-8.0.5.tgz#225322d7509c2157655840bba52e46b6c2f2fe33" integrity sha512-NTnHnVRd2JnRqPC0vW+iOQWU5pchDbYXsG2E6DMXEpMfUcQKclF9gmf3G3ZMhzG7IG9ji4coL0cm+FxeWxDpnw== @@ -14508,7 +14524,7 @@ resolve@1.17.0: dependencies: path-parse "^1.0.6" -resolve@^1.10.0, resolve@^1.14.2, resolve@^1.17.0, resolve@^1.19.0, resolve@^1.20.0, resolve@^1.8.1: +resolve@1.20.0, resolve@^1.10.0, resolve@^1.14.2, resolve@^1.17.0, resolve@^1.19.0, resolve@^1.20.0, resolve@^1.8.1: version "1.20.0" resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.20.0.tgz#629a013fb3f70755d6f0b7935cc1c2c5378b1975" integrity sha512-wENBPt4ySzg4ybFQW2TT1zMQucPK95HSh/nq2CFTZVOGut2+pQvSsgtda4d26YrYcr067wjbmzOG8byDPBX63A== @@ -14649,6 +14665,17 @@ rollup-plugin-typescript2@^0.29.0: resolve "1.17.0" tslib "2.0.1" +rollup-plugin-typescript2@^0.30.0: + version "0.30.0" + resolved "https://registry.yarnpkg.com/rollup-plugin-typescript2/-/rollup-plugin-typescript2-0.30.0.tgz#1cc99ac2309bf4b9d0a3ebdbc2002aecd56083d3" + integrity sha512-NUFszIQyhgDdhRS9ya/VEmsnpTe+GERDMmFo0Y+kf8ds51Xy57nPNGglJY+W6x1vcouA7Au7nsTgsLFj2I0PxQ== + dependencies: + "@rollup/pluginutils" "^4.1.0" + find-cache-dir "^3.3.1" + fs-extra "8.1.0" + resolve "1.20.0" + tslib "2.1.0" + rollup-pluginutils@^2.8.2: version "2.8.2" resolved "https://registry.yarnpkg.com/rollup-pluginutils/-/rollup-pluginutils-2.8.2.tgz#72f2af0748b592364dbd3389e600e5a9444a351e" @@ -16330,6 +16357,11 @@ tslib@2.0.1: resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.0.1.tgz#410eb0d113e5b6356490eec749603725b021b43e" integrity sha512-SgIkNheinmEBgx1IUNirK0TUD4X9yjjBRTqqjggWCU3pUEqIk3/Uwl3yRixYKT6WjQuGiwDv4NomL3wqRCj+CQ== +tslib@2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.1.0.tgz#da60860f1c2ecaa5703ab7d39bc05b6bf988b97a" + integrity sha512-hcVC3wYEziELGGmEEXue7D75zbwIIVUMWAVbHItGPx0ziyXxrOMQx4rQEVEV45Ut/1IotuEvwqPopzIOkDMf0A== + tslib@^1.6.0, tslib@^1.8.1, tslib@^1.9.0: version "1.14.1" resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"