From 8142704399efe6b4f34219c711a3932431781b36 Mon Sep 17 00:00:00 2001 From: Gino Zhang Date: Thu, 17 Dec 2020 23:27:18 +0800 Subject: [PATCH] Use user's typescript first, fallback to bundled (#741) * use process.cwd()'s typescript * use process.argv[1]'s instead of process.cwd()'s typescript * Handle situation that argv1 is empty * changeset * Require "typescript" from cwd i.o. argv1 --- .changeset/silver-guests-brake.md | 5 +++++ package-lock.json | 9 ++++++++- package.json | 1 + src/index.js | 6 +++++- 4 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 .changeset/silver-guests-brake.md diff --git a/.changeset/silver-guests-brake.md b/.changeset/silver-guests-brake.md new file mode 100644 index 00000000..9c36939e --- /dev/null +++ b/.changeset/silver-guests-brake.md @@ -0,0 +1,5 @@ +--- +'microbundle': minor +--- + +Use user's typescript first, fallback to bundled diff --git a/package-lock.json b/package-lock.json index 29ff7d3c..e193485a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "microbundle", - "version": "0.12.3", + "version": "0.12.4", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -9228,6 +9228,13 @@ "requires": { "parent-module": "^1.0.0", "resolve-from": "^4.0.0" + }, + "dependencies": { + "resolve-from": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", + "integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==" + } } }, "import-from": { diff --git a/package.json b/package.json index 5d4abf3b..1030c659 100644 --- a/package.json +++ b/package.json @@ -104,6 +104,7 @@ "lodash.merge": "^4.6.2", "module-details-from-path": "^1.0.3", "pretty-bytes": "^5.3.0", + "resolve-from": "^4.0.0", "rollup": "^1.32.1", "rollup-plugin-bundle-size": "^1.0.1", "rollup-plugin-es3": "^1.1.0", diff --git a/src/index.js b/src/index.js index 765bd0eb..599e2a06 100644 --- a/src/index.js +++ b/src/index.js @@ -9,6 +9,7 @@ import autoprefixer from 'autoprefixer'; import cssnano from 'cssnano'; import { rollup, watch } from 'rollup'; import builtinModules from 'builtin-modules'; +import resolveFrom from 'resolve-from'; import commonjs from '@rollup/plugin-commonjs'; import babel from '@rollup/plugin-babel'; import customBabel from './lib/babel-custom'; @@ -486,7 +487,10 @@ function createConfig(options, entry, format, writeMeta) { }, useTypescript && typescript({ - typescript: require('typescript'), + typescript: require(resolveFrom.silent( + options.cwd, + 'typescript', + ) || 'typescript'), cacheRoot: `./node_modules/.cache/.rts2_cache_${format}`, useTsconfigDeclarationDir: true, tsconfigDefaults: {