From 9d30063b1346fe6b17178574c2795b9174ae8857 Mon Sep 17 00:00:00 2001 From: Ryan Ling Date: Fri, 19 Jun 2020 01:48:05 +1000 Subject: [PATCH 1/2] Add warning for smt migrations --- .changeset/thin-tigers-hunt.md | 5 ++++ docs/migrating-from-seek-module-toolkit.md | 5 ++++ src/cli/configure/analyseDependencies.ts | 6 +++- src/cli/configure/analysis/package.ts | 31 ++++++++++++++++++++- src/cli/configure/dependencies/skubaDeps.ts | 3 +- src/cli/configure/getEntryPoint.ts | 2 ++ src/cli/configure/getProjectType.ts | 2 ++ 7 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 .changeset/thin-tigers-hunt.md diff --git a/.changeset/thin-tigers-hunt.md b/.changeset/thin-tigers-hunt.md new file mode 100644 index 000000000..9b6accfb6 --- /dev/null +++ b/.changeset/thin-tigers-hunt.md @@ -0,0 +1,5 @@ +--- +'skuba': patch +--- + +**configure:** Add notice for smt migrations diff --git a/docs/migrating-from-seek-module-toolkit.md b/docs/migrating-from-seek-module-toolkit.md index b8a3c0ff5..9674af157 100644 --- a/docs/migrating-from-seek-module-toolkit.md +++ b/docs/migrating-from-seek-module-toolkit.md @@ -51,6 +51,11 @@ You should remove workarounds such as: - Varying the referenced path of non-JS assets based on whether the code is source or compiled (i.e. using `__filename`). +Double check that your package is being bundled as you'd expect: + +1. Preview your bundle by running `yarn build`, then `npm pack` +1. Review the `files`, `main`, `module` and `types` fields in your `package.json` + ## Formatting and linting ```shell diff --git a/src/cli/configure/analyseDependencies.ts b/src/cli/configure/analyseDependencies.ts index 2e7234848..c26207880 100644 --- a/src/cli/configure/analyseDependencies.ts +++ b/src/cli/configure/analyseDependencies.ts @@ -8,7 +8,7 @@ import { TextProcessor, copyFiles } from '../../utils/copy'; import { log } from '../../utils/logging'; import { getSkubaVersion } from '../../utils/version'; -import { diffDependencies } from './analysis/package'; +import { diffDependencies, generateNotices } from './analysis/package'; import * as dependencyMutators from './dependencies'; import { formatPackage } from './processing/package'; import { DependencyDiff } from './types'; @@ -72,6 +72,8 @@ export const analyseDependencies = async ({ devDependencies: { ...input.devDependencies }, }; + const printNotices = generateNotices(input); + const processors = Object.values(dependencyMutators).reduce( (acc, mutate) => { const newProcessors = mutate(output); @@ -108,6 +110,8 @@ export const analyseDependencies = async ({ log.newline(); const hasDevDependencyDiff = logDiff(devDependencyDiff); + printNotices(); + const packageJsonFilepath = path.join(destinationRoot, 'package.json'); if (!hasDependencyDiff && !hasDevDependencyDiff) { diff --git a/src/cli/configure/analysis/package.ts b/src/cli/configure/analysis/package.ts index ac30bc4ad..175cd3bc2 100644 --- a/src/cli/configure/analysis/package.ts +++ b/src/cli/configure/analysis/package.ts @@ -1,7 +1,7 @@ import readPkgUp from 'read-pkg-up'; import { log } from '../../../utils/logging'; -import { DependencyDiff } from '../types'; +import { DependencyDiff, DependencySet } from '../types'; import { determineOperation } from './diff'; @@ -71,3 +71,32 @@ export const diffDependencies = ( ...additions, }; }; + +export const generateNotices = ({ + dependencies, + devDependencies, +}: DependencySet) => { + if ( + '@seek/seek-module-toolkit' in dependencies || + '@seek/seek-module-toolkit' in devDependencies + ) { + return () => { + log.newline(); + log.plain(`👋 Hello, ${log.bold('seek-module-toolkitter')}!`); + log.newline(); + log.warn( + "We're going to tweak your output directories,", + 'so double check your bundle once this is done.', + ); + log.newline(); + log.warn( + 'Read more:', + log.bold( + 'https://github.com/seek-oss/skuba/blob/master/docs/migrating-from-seek-module-toolkit.md#building', + ), + ); + }; + } + + return () => {}; +}; diff --git a/src/cli/configure/dependencies/skubaDeps.ts b/src/cli/configure/dependencies/skubaDeps.ts index 1f4f17621..7ca653f4f 100644 --- a/src/cli/configure/dependencies/skubaDeps.ts +++ b/src/cli/configure/dependencies/skubaDeps.ts @@ -21,8 +21,9 @@ const DEV_DEPENDENCIES = [ 'typescript', ] as const; -export const skubaDeps = ({ devDependencies }: DependencySet) => { +export const skubaDeps = ({ dependencies, devDependencies }: DependencySet) => { DEV_DEPENDENCIES.forEach((dep) => { + delete dependencies[dep]; delete devDependencies[dep]; }); diff --git a/src/cli/configure/getEntryPoint.ts b/src/cli/configure/getEntryPoint.ts index 1cd184fbb..6d15ff387 100644 --- a/src/cli/configure/getEntryPoint.ts +++ b/src/cli/configure/getEntryPoint.ts @@ -4,6 +4,7 @@ import chalk from 'chalk'; import { Input } from 'enquirer'; import { NormalizedReadResult } from 'read-pkg-up'; +import { log } from '../../utils/logging'; import { ProjectType } from '../../utils/manifest'; import { TemplateConfig } from '../../utils/template'; import { hasStringProp } from '../../utils/validation'; @@ -30,6 +31,7 @@ export const getEntryPoint = ({ return templateConfig.entryPoint; } + log.newline(); const entryPointPrompt = new Input({ initial: type === 'package' ? 'src/index.ts' : 'src/app.ts', message: 'Entry point:', diff --git a/src/cli/configure/getProjectType.ts b/src/cli/configure/getProjectType.ts index 56f02b4af..6bf2e29be 100644 --- a/src/cli/configure/getProjectType.ts +++ b/src/cli/configure/getProjectType.ts @@ -1,6 +1,7 @@ import { Select } from 'enquirer'; import { NormalizedReadResult } from 'read-pkg-up'; +import { log } from '../../utils/logging'; import { PROJECT_TYPES, ProjectType } from '../../utils/manifest'; import { TemplateConfig } from '../../utils/template'; import { hasProp } from '../../utils/validation'; @@ -31,6 +32,7 @@ export const getProjectType = async ({ ? 'package' : 'application'; + log.newline(); const projectTypePrompt = new Select({ choices: PROJECT_TYPES, message: 'Project type:', From d2baff28b9d1b9838d5c21720708a6c3a112c471 Mon Sep 17 00:00:00 2001 From: Ryan Ling Date: Fri, 19 Jun 2020 12:44:14 +1000 Subject: [PATCH 2/2] Improve migration instructions Co-authored-by: Ryan Cumming --- docs/migrating-from-seek-module-toolkit.md | 24 +++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/docs/migrating-from-seek-module-toolkit.md b/docs/migrating-from-seek-module-toolkit.md index 9674af157..1a632adc3 100644 --- a/docs/migrating-from-seek-module-toolkit.md +++ b/docs/migrating-from-seek-module-toolkit.md @@ -51,10 +51,28 @@ You should remove workarounds such as: - Varying the referenced path of non-JS assets based on whether the code is source or compiled (i.e. using `__filename`). -Double check that your package is being bundled as you'd expect: +After running `skuba configure`, +double check that the `package.json` fields look sensible. +Expect something like this: + +```jsonc +{ + "files": ["lib*/**/*.d.ts", "lib*/**/*.js", "lib*/**/*.js.map"], + "main": "./lib-commonjs/index.js", + "main": "./lib-es2015/index.js", + "types": "./lib-types/index.d.ts" +} +``` + +You may test out the packaging changes by either: + +- Pushing your changes to a `beta` Git branch, which releases a beta version on npm. + + In a consuming repo, you can then `yarn install` the beta version to give it a whirl. + +- Locally packaging with `yarn build`, then `npm pack`. -1. Preview your bundle by running `yarn build`, then `npm pack` -1. Review the `files`, `main`, `module` and `types` fields in your `package.json` + In a consuming repo, you can then `yarn add ../path/to/package.tgz` the local version to give it a whirl. ## Formatting and linting