Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(fix): set rootDir to './src', not './'. deprecate moveTypes #504

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
2441508
(fix/refactor): rewrite some overbroad try/catches
agilgur5 Feb 7, 2020
ee93967
(fix): set rootDir to './src', not './'. deprecate moveTypes
agilgur5 Feb 11, 2020
fde984a
(empty/removeme): test CI again 1
agilgur5 Feb 11, 2020
ca64208
(empty/removeme): test CI again 2
agilgur5 Feb 11, 2020
c7d06f6
(empty/removeme): test CI again 3
agilgur5 Feb 11, 2020
f6733f7
(empty/removeme): test CI again 4
agilgur5 Feb 11, 2020
9ac0074
(empty/removeme): test CI again 5
agilgur5 Feb 11, 2020
41bc75c
(empty/removeme): test CI again 6
agilgur5 Feb 11, 2020
e0e6943
(empty/removeme): test CI again 7
agilgur5 Feb 11, 2020
4673944
(empty/removeme): test CI again 8
agilgur5 Feb 11, 2020
163a31a
(empty/removeme): test CI again 9
agilgur5 Feb 11, 2020
aba00c2
(empty/removeme): test CI again 10
agilgur5 Feb 11, 2020
2add8b0
(empty/removeme): test CI again 11
agilgur5 Feb 11, 2020
85d084a
(empty/removeme): test CI again 12
agilgur5 Feb 11, 2020
3723ada
(empty/removeme): test CI again 13
agilgur5 Feb 11, 2020
8f85df5
(empty/removeme): test CI again 14
agilgur5 Feb 11, 2020
41cd03a
(empty/removeme): test CI again 15
agilgur5 Feb 11, 2020
499addf
(empty/removeme): test CI again 16
agilgur5 Feb 11, 2020
5b44949
(empty/removeme): test CI again 17
agilgur5 Feb 11, 2020
69e89bd
(empty/removeme): test CI again 18
agilgur5 Feb 11, 2020
34d67b5
(empty/removeme): test CI again 19
agilgur5 Feb 11, 2020
d8e35cd
(empty/removeme): test CI again 20
agilgur5 Feb 11, 2020
bfa6558
(empty/removeme): test CI again 21
agilgur5 Feb 11, 2020
4663e56
(empty/removeme): test CI again 22
agilgur5 Feb 11, 2020
c47e996
(empty/removeme): test CI again 23
agilgur5 Feb 11, 2020
5b01f14
(empty/removeme): test CI again 24
agilgur5 Feb 11, 2020
afc46fe
(empty/removeme): test CI again 25
agilgur5 Feb 11, 2020
75b349a
(empty/removeme): test CI again 26
agilgur5 Feb 11, 2020
c86c8ee
(empty/removeme): test CI again 27
agilgur5 Feb 11, 2020
b290fea
(empty/removeme): test CI again 28
agilgur5 Feb 11, 2020
2f763c5
(empty/removeme): test CI again 29
agilgur5 Feb 11, 2020
098e2ec
(empty/removeme): test CI again 30
agilgur5 Feb 11, 2020
6000ba2
(empty/removeme): test CI again 31
agilgur5 Feb 11, 2020
82abf5a
(empty/removeme): test CI again 32
agilgur5 Feb 11, 2020
b223d0a
(empty/removeme): test CI again 33
agilgur5 Feb 11, 2020
ce488a5
more descriptive warning about bugs, fixup with (fix): set rootDir to…
agilgur5 Feb 11, 2020
2ed83d3
(empty/removeme): test CI again 34
agilgur5 Feb 11, 2020
f6a0b4d
(empty/removeme): test CI again 35
agilgur5 Feb 11, 2020
2fe4957
(empty/removeme): test CI again 36
agilgur5 Feb 11, 2020
e2952ee
(empty/removeme): test CI again 37
agilgur5 Feb 11, 2020
24d5709
(empty/removeme): test CI again 38
agilgur5 Feb 11, 2020
4b4a762
add a comment that the catch is the problem, fixup with (fix): set ro…
agilgur5 Feb 11, 2020
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
45 changes: 45 additions & 0 deletions src/deprecated.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
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 ' +
'"./" as it caused buggy output for declarationMaps and occassionally ' +
'for type declarations themselves.'
jaredpalmer marked this conversation as resolved.
Show resolved Hide resolved
);

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
// 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;
}
}

await fs.remove(appDistSrc);
}
36 changes: 7 additions & 29 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -48,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');
Expand Down Expand Up @@ -101,16 +100,6 @@ async function getInputs(
return concatAllArray(inputs);
}

async function moveTypes() {
try {
// Move the typescript types to the base of the ./dist folder
await fs.copy(paths.appDist + '/src', paths.appDist, {
overwrite: true,
});
await fs.remove(paths.appDist + '/src');
} catch (e) {}
}

prog
.version(pkg.version)
.command('create <pkg>')
Expand Down Expand Up @@ -140,16 +129,11 @@ prog
// Helper fn to prompt the user for a different
// folder name if one already exists
async function getProjectPath(projectPath: string): Promise<string> {
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(
Expand All @@ -158,6 +142,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)}...`);
Expand Down Expand Up @@ -373,7 +358,7 @@ prog
`);

try {
await moveTypes();
await deprecated.moveTypes();

if (firstTime && opts.onFirstSuccess) {
firstTime = false;
Expand Down Expand Up @@ -424,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) => {
Expand Down Expand Up @@ -453,14 +438,7 @@ async function normalizeOpts(opts: WatchOpts): Promise<NormalizedOpts> {
}

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) {
Expand Down
2 changes: 1 addition & 1 deletion templates/basic/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"importHelpers": true,
"declaration": true,
"sourceMap": true,
"rootDir": "./",
"rootDir": "./src",
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
Expand Down
2 changes: 1 addition & 1 deletion templates/react-with-storybook/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"importHelpers": true,
"declaration": true,
"sourceMap": true,
"rootDir": "./",
"rootDir": "./src",
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
Expand Down
2 changes: 1 addition & 1 deletion templates/react/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"importHelpers": true,
"declaration": true,
"sourceMap": true,
"rootDir": "./",
"rootDir": "./src",
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/build-default/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"lib": ["dom", "esnext"],
"declaration": true,
"sourceMap": true,
"rootDir": "./",
"rootDir": "./src",
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/build-invalid/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"lib": ["dom", "esnext"],
"declaration": true,
"sourceMap": true,
"rootDir": "./",
"rootDir": "./src",
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/build-withConfig/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"lib": ["dom", "esnext"],
"declaration": true,
"sourceMap": true,
"rootDir": "./",
"rootDir": "./src",
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
Expand Down