From 2441508da787f88c8b869615843513357b113350 Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Fri, 7 Feb 2020 01:58:40 -0500 Subject: [PATCH 01/42] (fix/refactor): rewrite some overbroad try/catches - so there's less silent failures that occur but don't error - replace overbroad try/catch in getProjectPath with just an fs.pathExists - replace overbroad try/catch in cleanDistFolder with just an fs.remove - fs.remove is like rimraf and `rm -rf` in that it won't error if the file/dir doesn't exist - if it does error, it's probably because it *failed* to remove the dir, and that should error, because it's potentially a problem, especially if you're publishing right after - rewrite moveTypes() so it doesn't have an overbroad try/catch - use fs.pathExists first and early return if it doesn't exist - only check for known errors with fs.copy, and rethrow others - this way if copy or remove actually fail, they will actually error - before they would silently fail, which could similarly be pretty bad if one were to publish right after a silent failure --- src/index.ts | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/index.ts b/src/index.ts index de4d97b97..d2fc000d5 100755 --- a/src/index.ts +++ b/src/index.ts @@ -12,13 +12,11 @@ import { } from 'rollup'; import asyncro from 'asyncro'; import chalk from 'chalk'; -import util from 'util'; import * as fs from 'fs-extra'; import jest from 'jest'; import { CLIEngine } from 'eslint'; import logError from './logError'; import path from 'path'; -import rimraf from 'rimraf'; import execa from 'execa'; import shell from 'shelljs'; import ora from 'ora'; @@ -102,13 +100,26 @@ async function getInputs( } async function moveTypes() { + const appDistSrc = paths.appDist + '/src'; + + const pathExists = await fs.pathExists(appDistSrc); + if (!pathExists) return; + try { // Move the typescript types to the base of the ./dist folder - await fs.copy(paths.appDist + '/src', paths.appDist, { + await fs.copy(appDistSrc, paths.appDist, { overwrite: true, }); - await fs.remove(paths.appDist + '/src'); - } catch (e) {} + } catch (err) { + // ignore errors about the destination dir already existing or files not + // existing as those always occur for some reason, re-throw any other + // unexpected failures + if (err.code !== 'EEXIST' && err.code !== 'ENOENT') { + throw err; + } + } + + await fs.remove(appDistSrc); } prog @@ -140,16 +151,11 @@ prog // Helper fn to prompt the user for a different // folder name if one already exists async function getProjectPath(projectPath: string): Promise { - let exists = true; - try { - // will throw an exception if it does not exists - await util.promisify(fs.access)(projectPath); - } catch { - exists = false; - } + const exists = await fs.pathExists(projectPath); if (!exists) { return projectPath; } + bootSpinner.fail(`Failed to create ${chalk.bold.red(pkg)}`); const prompt = new Input({ message: `A folder named ${chalk.bold.red( @@ -158,6 +164,7 @@ prog initial: pkg + '-1', result: (v: string) => v.trim(), }); + pkg = await prompt.run(); projectPath = (await fs.realpath(process.cwd())) + '/' + pkg; bootSpinner.start(`Creating ${chalk.bold.green(pkg)}...`); @@ -453,14 +460,7 @@ async function normalizeOpts(opts: WatchOpts): Promise { } async function cleanDistFolder() { - try { - await util.promisify(fs.access)(paths.appDist); - return util.promisify(rimraf)(paths.appDist); - } catch { - // if an exception is throw, the files does not exists or it is not visible - // either way, we just return - return; - } + await fs.remove(paths.appDist); } function writeCjsEntryFile(name: string) { From ee9396792a12c2b76811bd0d5513251a6ae239bd Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Mon, 10 Feb 2020 22:10:38 -0500 Subject: [PATCH 02/42] (fix): set rootDir to './src', not './'. deprecate moveTypes - rootDir needed to be changed to ./src because the previous ./ caused type declarations to be generated in dist/src/ instead of just dist/ - the moveTypes function handled moving the declarations back into dist/, but occassionally had errors moving .d.ts files - particularly in CI and for projects with many of them - declarationMap (*.d.ts.map) files would also have issues due to the hackiness of moveTypes, setting to rootDir to './src' is one of the necessary steps in fixing them - deprecate moveTypes and add a warning with instructions if it is used when a rootDir of './' is detected - add notes about a deprecation window in the comments --- src/deprecated.ts | 41 ++++++++++++++++++++ src/index.ts | 28 ++----------- templates/basic/tsconfig.json | 2 +- templates/react-with-storybook/tsconfig.json | 2 +- templates/react/tsconfig.json | 2 +- test/fixtures/build-default/tsconfig.json | 2 +- test/fixtures/build-invalid/tsconfig.json | 2 +- test/fixtures/build-withConfig/tsconfig.json | 2 +- 8 files changed, 50 insertions(+), 31 deletions(-) create mode 100644 src/deprecated.ts diff --git a/src/deprecated.ts b/src/deprecated.ts new file mode 100644 index 000000000..3f9f83319 --- /dev/null +++ b/src/deprecated.ts @@ -0,0 +1,41 @@ +import * as fs from 'fs-extra'; + +import { paths } from './constants'; + +/* + This was originally needed because the default + tsconfig.compilerOptions.rootDir was set to './' instead of './src'. + Now that it's set to './src', this is now deprecated. + To ensure a stable upgrade path for users, leave the warning in for + 6 months - 1 year, then change it to an error in a breaking bump and leave + that in for some time too. +*/ +export async function moveTypes() { + const appDistSrc = paths.appDist + '/src'; + + const pathExists = await fs.pathExists(appDistSrc); + if (!pathExists) return; + + // see note above about deprecation window + console.warn( + '[tsdx]: Your rootDir is currently set to "./". Please change your ' + + 'rootDir to "./src".\n' + + 'TSDX has deprecated setting tsconfig.compilerOptions.rootDir to "./".' + ); + + try { + // Move the typescript types to the base of the ./dist folder + await fs.copy(appDistSrc, paths.appDist, { + overwrite: true, + }); + } catch (err) { + // ignore errors about the destination dir already existing or files not + // existing as those always occur for some reason, re-throw any other + // unexpected failures + if (err.code !== 'EEXIST' && err.code !== 'ENOENT') { + throw err; + } + } + + await fs.remove(appDistSrc); +} diff --git a/src/index.ts b/src/index.ts index d2fc000d5..9a44da920 100755 --- a/src/index.ts +++ b/src/index.ts @@ -46,6 +46,7 @@ import { import { createProgressEstimator } from './createProgressEstimator'; import { templates } from './templates'; import { composePackageJson } from './templates/utils'; +import * as deprecated from './deprecated'; const pkg = require('../package.json'); const prog = sade('tsdx'); @@ -99,29 +100,6 @@ async function getInputs( return concatAllArray(inputs); } -async function moveTypes() { - const appDistSrc = paths.appDist + '/src'; - - const pathExists = await fs.pathExists(appDistSrc); - if (!pathExists) return; - - try { - // Move the typescript types to the base of the ./dist folder - await fs.copy(appDistSrc, paths.appDist, { - overwrite: true, - }); - } catch (err) { - // ignore errors about the destination dir already existing or files not - // existing as those always occur for some reason, re-throw any other - // unexpected failures - if (err.code !== 'EEXIST' && err.code !== 'ENOENT') { - throw err; - } - } - - await fs.remove(appDistSrc); -} - prog .version(pkg.version) .command('create ') @@ -380,7 +358,7 @@ prog `); try { - await moveTypes(); + await deprecated.moveTypes(); if (firstTime && opts.onFirstSuccess) { firstTime = false; @@ -431,7 +409,7 @@ prog async (inputOptions: RollupOptions & { output: OutputOptions }) => { let bundle = await rollup(inputOptions); await bundle.write(inputOptions.output); - await moveTypes(); + await deprecated.moveTypes(); } ) .catch((e: any) => { diff --git a/templates/basic/tsconfig.json b/templates/basic/tsconfig.json index 0fbd5f582..a63b7e132 100644 --- a/templates/basic/tsconfig.json +++ b/templates/basic/tsconfig.json @@ -6,7 +6,7 @@ "importHelpers": true, "declaration": true, "sourceMap": true, - "rootDir": "./", + "rootDir": "./src", "strict": true, "noImplicitAny": true, "strictNullChecks": true, diff --git a/templates/react-with-storybook/tsconfig.json b/templates/react-with-storybook/tsconfig.json index 3eb378a0d..e0b677e59 100644 --- a/templates/react-with-storybook/tsconfig.json +++ b/templates/react-with-storybook/tsconfig.json @@ -6,7 +6,7 @@ "importHelpers": true, "declaration": true, "sourceMap": true, - "rootDir": "./", + "rootDir": "./src", "strict": true, "noImplicitAny": true, "strictNullChecks": true, diff --git a/templates/react/tsconfig.json b/templates/react/tsconfig.json index 0fbd5f582..a63b7e132 100644 --- a/templates/react/tsconfig.json +++ b/templates/react/tsconfig.json @@ -6,7 +6,7 @@ "importHelpers": true, "declaration": true, "sourceMap": true, - "rootDir": "./", + "rootDir": "./src", "strict": true, "noImplicitAny": true, "strictNullChecks": true, diff --git a/test/fixtures/build-default/tsconfig.json b/test/fixtures/build-default/tsconfig.json index d8ff04c12..7f2bd50c5 100644 --- a/test/fixtures/build-default/tsconfig.json +++ b/test/fixtures/build-default/tsconfig.json @@ -4,7 +4,7 @@ "lib": ["dom", "esnext"], "declaration": true, "sourceMap": true, - "rootDir": "./", + "rootDir": "./src", "strict": true, "noImplicitAny": true, "strictNullChecks": true, diff --git a/test/fixtures/build-invalid/tsconfig.json b/test/fixtures/build-invalid/tsconfig.json index d8ff04c12..7f2bd50c5 100644 --- a/test/fixtures/build-invalid/tsconfig.json +++ b/test/fixtures/build-invalid/tsconfig.json @@ -4,7 +4,7 @@ "lib": ["dom", "esnext"], "declaration": true, "sourceMap": true, - "rootDir": "./", + "rootDir": "./src", "strict": true, "noImplicitAny": true, "strictNullChecks": true, diff --git a/test/fixtures/build-withConfig/tsconfig.json b/test/fixtures/build-withConfig/tsconfig.json index 43e3ec95f..a8c8432ed 100644 --- a/test/fixtures/build-withConfig/tsconfig.json +++ b/test/fixtures/build-withConfig/tsconfig.json @@ -4,7 +4,7 @@ "lib": ["dom", "esnext"], "declaration": true, "sourceMap": true, - "rootDir": "./", + "rootDir": "./src", "strict": true, "noImplicitAny": true, "strictNullChecks": true, From fde984a00912c7355f99d5c5740a5956c1ab3ceb Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Mon, 10 Feb 2020 22:31:22 -0500 Subject: [PATCH 03/42] (empty/removeme): test CI again 1 From ca642082e76e58875f3dd03df1b4e68e19d25568 Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Mon, 10 Feb 2020 22:36:58 -0500 Subject: [PATCH 04/42] (empty/removeme): test CI again 2 From c7d06f601260f24e37e0b92be458efcf1a1cd323 Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Mon, 10 Feb 2020 22:38:03 -0500 Subject: [PATCH 05/42] (empty/removeme): test CI again 3 From f6733f72b0983ccb983eced6c3562e91dba3b56a Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Mon, 10 Feb 2020 22:39:30 -0500 Subject: [PATCH 06/42] (empty/removeme): test CI again 4 From 9ac00749563f167a92a49bb361042569b96c7be7 Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Mon, 10 Feb 2020 22:41:45 -0500 Subject: [PATCH 07/42] (empty/removeme): test CI again 5 From 41bc75c99eb3fa3fd6201298743429a4b40fc56a Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Mon, 10 Feb 2020 22:43:58 -0500 Subject: [PATCH 08/42] (empty/removeme): test CI again 6 From e0e6943cfcac6b9aa79452a7430201563003a249 Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Mon, 10 Feb 2020 22:45:26 -0500 Subject: [PATCH 09/42] (empty/removeme): test CI again 7 From 467394447d65564dbad2d47ba1ff650e84081ad3 Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Mon, 10 Feb 2020 22:47:22 -0500 Subject: [PATCH 10/42] (empty/removeme): test CI again 8 From 163a31ac974e2ee781ef80cce49523e9130a05de Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Mon, 10 Feb 2020 22:49:26 -0500 Subject: [PATCH 11/42] (empty/removeme): test CI again 9 From aba00c21f05b116d7857cac827a733df8d0f3e61 Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Mon, 10 Feb 2020 22:50:49 -0500 Subject: [PATCH 12/42] (empty/removeme): test CI again 10 From 2add8b0bfcf4020bd58789937b11405c39819121 Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Mon, 10 Feb 2020 22:54:15 -0500 Subject: [PATCH 13/42] (empty/removeme): test CI again 11 From 85d084af7f8f2c030fdb645aab9317306d29e7a0 Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Mon, 10 Feb 2020 22:54:50 -0500 Subject: [PATCH 14/42] (empty/removeme): test CI again 12 From 3723ada254dd0c08a46c0a244ef8c9808510ce2d Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Mon, 10 Feb 2020 22:56:53 -0500 Subject: [PATCH 15/42] (empty/removeme): test CI again 13 From 8f85df5e0868db3a9a70068fe791bb195fa23268 Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Mon, 10 Feb 2020 22:58:43 -0500 Subject: [PATCH 16/42] (empty/removeme): test CI again 14 From 41cd03a3af9f23d499e3ff7e31f15cdf49342303 Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Mon, 10 Feb 2020 23:00:00 -0500 Subject: [PATCH 17/42] (empty/removeme): test CI again 15 From 499addf7010176315640b524aefe6940b63ba674 Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Mon, 10 Feb 2020 23:01:34 -0500 Subject: [PATCH 18/42] (empty/removeme): test CI again 16 From 5b4494942b136ff6e0dc83da2524d1f099713efd Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Mon, 10 Feb 2020 23:02:53 -0500 Subject: [PATCH 19/42] (empty/removeme): test CI again 17 From 69e89bdd58d4a6fa61b01246627e17fd119947d5 Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Mon, 10 Feb 2020 23:04:28 -0500 Subject: [PATCH 20/42] (empty/removeme): test CI again 18 From 34d67b5198932d4dc03e1e7476601eb0e6b83a2b Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Mon, 10 Feb 2020 23:06:00 -0500 Subject: [PATCH 21/42] (empty/removeme): test CI again 19 From d8e35cdac75e6633e7155f524c891f377bff7ca8 Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Mon, 10 Feb 2020 23:07:44 -0500 Subject: [PATCH 22/42] (empty/removeme): test CI again 20 From bfa6558517c5b42daa5a57a1916b4788d0fc6d09 Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Mon, 10 Feb 2020 23:09:37 -0500 Subject: [PATCH 23/42] (empty/removeme): test CI again 21 From 4663e564820d2ed6667822f9e63c92d039bb24ab Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Mon, 10 Feb 2020 23:10:51 -0500 Subject: [PATCH 24/42] (empty/removeme): test CI again 22 From c47e99680bbc730b5def283f096d1551d8660930 Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Mon, 10 Feb 2020 23:14:23 -0500 Subject: [PATCH 25/42] (empty/removeme): test CI again 23 From 5b01f1467298e63189cef2e6561656bcd1d367fe Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Mon, 10 Feb 2020 23:14:38 -0500 Subject: [PATCH 26/42] (empty/removeme): test CI again 24 From afc46fe7db63f208a67b8a0073e297c90456ad9c Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Mon, 10 Feb 2020 23:17:56 -0500 Subject: [PATCH 27/42] (empty/removeme): test CI again 25 From 75b349a9ef20d288dd22f4876f42f650ba6b3717 Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Mon, 10 Feb 2020 23:18:14 -0500 Subject: [PATCH 28/42] (empty/removeme): test CI again 26 From c86c8ee922edc3b69395cedd51859c3cf68f2561 Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Mon, 10 Feb 2020 23:20:36 -0500 Subject: [PATCH 29/42] (empty/removeme): test CI again 27 From b290feaf97f8905ca1f26e2192e2a975a7f8e1eb Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Mon, 10 Feb 2020 23:23:34 -0500 Subject: [PATCH 30/42] (empty/removeme): test CI again 28 From 2f763c518368714d9731a55c7c503d592fe8f2ba Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Mon, 10 Feb 2020 23:23:48 -0500 Subject: [PATCH 31/42] (empty/removeme): test CI again 29 From 098e2eca14835aabcb957a07204764d0a7c3ab7d Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Mon, 10 Feb 2020 23:25:01 -0500 Subject: [PATCH 32/42] (empty/removeme): test CI again 30 From 6000ba2dad3bf2ac6be52689cc71eda7598381a0 Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Mon, 10 Feb 2020 23:27:05 -0500 Subject: [PATCH 33/42] (empty/removeme): test CI again 31 From 82abf5a8fc756cab4ae8664df48e409aea99bae0 Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Mon, 10 Feb 2020 23:29:30 -0500 Subject: [PATCH 34/42] (empty/removeme): test CI again 32 From b223d0ab001b2200fae24db6e6837f6ea26e1fcc Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Mon, 10 Feb 2020 23:32:18 -0500 Subject: [PATCH 35/42] (empty/removeme): test CI again 33 From ce488a5ab38509e2657d29c342d0ede5c2194ed0 Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Mon, 10 Feb 2020 23:34:35 -0500 Subject: [PATCH 36/42] more descriptive warning about bugs, fixup with (fix): set rootDir to './src', not './'. deprecate moveTypes --- src/deprecated.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/deprecated.ts b/src/deprecated.ts index 3f9f83319..43d1fa477 100644 --- a/src/deprecated.ts +++ b/src/deprecated.ts @@ -20,7 +20,9 @@ export async function moveTypes() { console.warn( '[tsdx]: Your rootDir is currently set to "./". Please change your ' + 'rootDir to "./src".\n' + - 'TSDX has deprecated setting tsconfig.compilerOptions.rootDir to "./".' + 'TSDX has deprecated setting tsconfig.compilerOptions.rootDir to ' + + '"./" as it caused buggy output for declarationMaps and occassionally ' + + 'for type declarations themselves.' ); try { From 2ed83d3aab053c2b2643a0b93947a892ce102d32 Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Mon, 10 Feb 2020 23:35:45 -0500 Subject: [PATCH 37/42] (empty/removeme): test CI again 34 From f6a0b4da013fa23b26b771fbded20d855808e5cd Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Mon, 10 Feb 2020 23:36:46 -0500 Subject: [PATCH 38/42] (empty/removeme): test CI again 35 From 2fe4957a4454df685a431771baab727086e1883b Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Mon, 10 Feb 2020 23:38:17 -0500 Subject: [PATCH 39/42] (empty/removeme): test CI again 36 From e2952ee80e4599ade55167ab91f7db65e0b75e1a Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Mon, 10 Feb 2020 23:39:14 -0500 Subject: [PATCH 40/42] (empty/removeme): test CI again 37 From 24d57099afcb89837cfddb0a67c5d507e7a1eda0 Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Mon, 10 Feb 2020 23:40:51 -0500 Subject: [PATCH 41/42] (empty/removeme): test CI again 38 From 4b4a762133b27d3a1fee4b870ec3c088a275d464 Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Tue, 11 Feb 2020 01:13:10 -0500 Subject: [PATCH 42/42] add a comment that the catch is the problem, fixup with (fix): set rootDir to './src', not './'. deprecate moveTypes --- src/deprecated.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/deprecated.ts b/src/deprecated.ts index 43d1fa477..1eb9cc550 100644 --- a/src/deprecated.ts +++ b/src/deprecated.ts @@ -34,6 +34,8 @@ export async function moveTypes() { // ignore errors about the destination dir already existing or files not // existing as those always occur for some reason, re-throw any other // unexpected failures + // NOTE: these errors mean that sometimes files don't get moved properly, + // meaning that it's buggy / unreliable (see console.warn above) if (err.code !== 'EEXIST' && err.code !== 'ENOENT') { throw err; }