From dfe6641d4b3590d8b0cbf5835a50c1f2b54b9562 Mon Sep 17 00:00:00 2001 From: ijlee2 Date: Wed, 18 Jan 2023 08:18:39 +0100 Subject: [PATCH 1/6] chore: Fixed typos --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0049d110..1ac69cc4 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ _Codemod to convert Ember addons to v2 addon format_ - Switches Ember's "magic" import paths to relative paths - Preserves your code whenever possible - Supports [`ember-cli-typescript`](https://docs.ember-cli-typescript.com/) and [`glint`](https://typed-ember.gitbook.io/glint/) -- Focuses on maintainbility and extensibility +- Focuses on maintainability and extensibility ## Usage From efa13939755f41bb564d4e8a66f23341df9c74a5 Mon Sep 17 00:00:00 2001 From: ijlee2 Date: Wed, 18 Jan 2023 08:34:40 +0100 Subject: [PATCH 2/6] refactor: Asserted the existence of the package version. Renamed test files and simplified the test setup. --- .../ember-addon/steps/augment-options.js | 10 ++++- .../augment-options/custom-locations.test.js | 2 +- ...ing-package-json-is-an-empty-file.test.js} | 4 +- ...-package-json-is-not-a-valid-json.test.js} | 8 ++-- ...-handling-package-name-is-missing.test.js} | 6 +-- ...andling-package-name-is-not-valid.test.js} | 12 +----- ...andling-package-version-is-missing.test.js | 38 +++++++++++++++++++ .../steps/augment-options/glint.test.js | 2 +- .../steps/augment-options/javascript.test.js | 2 +- .../steps/augment-options/npm.test.js | 2 +- .../steps/augment-options/pnpm.test.js | 2 +- .../augment-options/scoped-package.test.js | 2 +- .../steps/augment-options/typescript.test.js | 2 +- .../steps/augment-options/v2-addon.test.js | 2 +- 14 files changed, 65 insertions(+), 29 deletions(-) rename tests/migration/ember-addon/steps/augment-options/{error-handling-1.test.js => error-handling-package-json-is-an-empty-file.test.js} (90%) rename tests/migration/ember-addon/steps/augment-options/{error-handling-3.test.js => error-handling-package-json-is-not-a-valid-json.test.js} (80%) rename tests/migration/ember-addon/steps/augment-options/{error-handling-2.test.js => error-handling-package-name-is-missing.test.js} (80%) rename tests/migration/ember-addon/steps/augment-options/{error-handling-4.test.js => error-handling-package-name-is-not-valid.test.js} (72%) create mode 100644 tests/migration/ember-addon/steps/augment-options/error-handling-package-version-is-missing.test.js diff --git a/src/migration/ember-addon/steps/augment-options.js b/src/migration/ember-addon/steps/augment-options.js index 4e32f65a..eae0f745 100644 --- a/src/migration/ember-addon/steps/augment-options.js +++ b/src/migration/ember-addon/steps/augment-options.js @@ -68,8 +68,14 @@ function analyzePackageManager(options) { function deriveAddonLocation(addonPackage) { if (!addonPackage.name) { - throw new RangeError( - `ERROR: In package.json, the package name \`${addonPackage.name}\` is not valid.` + throw new SyntaxError( + 'ERROR: In package.json, the package name is missing.' + ); + } + + if (!addonPackage.version) { + throw new SyntaxError( + 'ERROR: In package.json, the package version is missing.' ); } diff --git a/tests/migration/ember-addon/steps/augment-options/custom-locations.test.js b/tests/migration/ember-addon/steps/augment-options/custom-locations.test.js index a7d65aa7..e4bafb5e 100644 --- a/tests/migration/ember-addon/steps/augment-options/custom-locations.test.js +++ b/tests/migration/ember-addon/steps/augment-options/custom-locations.test.js @@ -26,7 +26,7 @@ test('migration | ember-addon | steps | augment-options > custom locations', fun null, 2 ), - 'yarn.lock': 'some code for yarn.lock', + 'yarn.lock': '', }; loadFixture(inputProject, options); diff --git a/tests/migration/ember-addon/steps/augment-options/error-handling-1.test.js b/tests/migration/ember-addon/steps/augment-options/error-handling-package-json-is-an-empty-file.test.js similarity index 90% rename from tests/migration/ember-addon/steps/augment-options/error-handling-1.test.js rename to tests/migration/ember-addon/steps/augment-options/error-handling-package-json-is-an-empty-file.test.js index fe20ec5e..d14db6e4 100644 --- a/tests/migration/ember-addon/steps/augment-options/error-handling-1.test.js +++ b/tests/migration/ember-addon/steps/augment-options/error-handling-package-json-is-an-empty-file.test.js @@ -1,7 +1,7 @@ import { augmentOptions } from '../../../../../src/migration/ember-addon/steps/augment-options.js'; import { assert, loadFixture, test } from '../../../../test-helpers.js'; -test('migration | ember-addon | steps | augment-options > error handling (empty file)', function () { +test('migration | ember-addon | steps | augment-options > error handling (package.json is an empty file)', function () { const options = { addonLocation: undefined, projectRoot: 'tmp/new-v1-addon-javascript', @@ -11,7 +11,7 @@ test('migration | ember-addon | steps | augment-options > error handling (empty const inputProject = { 'package.json': '', - 'yarn.lock': 'some code for yarn.lock', + 'yarn.lock': '', }; loadFixture(inputProject, options); diff --git a/tests/migration/ember-addon/steps/augment-options/error-handling-3.test.js b/tests/migration/ember-addon/steps/augment-options/error-handling-package-json-is-not-a-valid-json.test.js similarity index 80% rename from tests/migration/ember-addon/steps/augment-options/error-handling-3.test.js rename to tests/migration/ember-addon/steps/augment-options/error-handling-package-json-is-not-a-valid-json.test.js index c758ffc6..a829c8e2 100644 --- a/tests/migration/ember-addon/steps/augment-options/error-handling-3.test.js +++ b/tests/migration/ember-addon/steps/augment-options/error-handling-package-json-is-not-a-valid-json.test.js @@ -1,7 +1,7 @@ import { augmentOptions } from '../../../../../src/migration/ember-addon/steps/augment-options.js'; import { assert, loadFixture, test } from '../../../../test-helpers.js'; -test('migration | ember-addon | steps | augment-options > error handling (corrupt package.json)', function () { +test('migration | ember-addon | steps | augment-options > error handling (package.json is not a valid JSON)', function () { const options = { addonLocation: undefined, projectRoot: 'tmp/new-v1-addon-javascript', @@ -10,8 +10,8 @@ test('migration | ember-addon | steps | augment-options > error handling (corrup }; const inputProject = { - 'package.json': '{\n name:}', - 'yarn.lock': 'some code for yarn.lock', + 'package.json': '{\n "name": }', + 'yarn.lock': '', }; loadFixture(inputProject, options); @@ -23,7 +23,7 @@ test('migration | ember-addon | steps | augment-options > error handling (corrup (error) => { assert.strictEqual( error.message, - 'ERROR: package.json is missing or is not a valid JSON. (Unexpected token n in JSON at position 4)\n' + 'ERROR: package.json is missing or is not a valid JSON. (Unexpected token } in JSON at position 12)\n' ); return true; diff --git a/tests/migration/ember-addon/steps/augment-options/error-handling-2.test.js b/tests/migration/ember-addon/steps/augment-options/error-handling-package-name-is-missing.test.js similarity index 80% rename from tests/migration/ember-addon/steps/augment-options/error-handling-2.test.js rename to tests/migration/ember-addon/steps/augment-options/error-handling-package-name-is-missing.test.js index 7a40d327..f40bd7cd 100644 --- a/tests/migration/ember-addon/steps/augment-options/error-handling-2.test.js +++ b/tests/migration/ember-addon/steps/augment-options/error-handling-package-name-is-missing.test.js @@ -1,7 +1,7 @@ import { augmentOptions } from '../../../../../src/migration/ember-addon/steps/augment-options.js'; import { assert, loadFixture, test } from '../../../../test-helpers.js'; -test('migration | ember-addon | steps | augment-options > error handling (empty object)', function () { +test('migration | ember-addon | steps | augment-options > error handling (package name is missing)', function () { const options = { addonLocation: undefined, projectRoot: 'tmp/new-v1-addon-javascript', @@ -11,7 +11,7 @@ test('migration | ember-addon | steps | augment-options > error handling (empty const inputProject = { 'package.json': '{}', - 'yarn.lock': 'some code for yarn.lock', + 'yarn.lock': '', }; loadFixture(inputProject, options); @@ -23,7 +23,7 @@ test('migration | ember-addon | steps | augment-options > error handling (empty (error) => { assert.strictEqual( error.message, - 'ERROR: In package.json, the package name `undefined` is not valid.' + 'ERROR: In package.json, the package name is missing.' ); return true; diff --git a/tests/migration/ember-addon/steps/augment-options/error-handling-4.test.js b/tests/migration/ember-addon/steps/augment-options/error-handling-package-name-is-not-valid.test.js similarity index 72% rename from tests/migration/ember-addon/steps/augment-options/error-handling-4.test.js rename to tests/migration/ember-addon/steps/augment-options/error-handling-package-name-is-not-valid.test.js index 7492cfca..c31cb4dd 100644 --- a/tests/migration/ember-addon/steps/augment-options/error-handling-4.test.js +++ b/tests/migration/ember-addon/steps/augment-options/error-handling-package-name-is-not-valid.test.js @@ -1,7 +1,7 @@ import { augmentOptions } from '../../../../../src/migration/ember-addon/steps/augment-options.js'; import { assert, loadFixture, test } from '../../../../test-helpers.js'; -test('migration | ember-addon | steps | augment-options > error handling (incorrect scoped package name)', function () { +test('migration | ember-addon | steps | augment-options > error handling (package name is not valid)', function () { const options = { addonLocation: undefined, projectRoot: 'tmp/new-v1-addon-javascript', @@ -14,19 +14,11 @@ test('migration | ember-addon | steps | augment-options > error handling (incorr { name: '@ijlee2/', version: '0.0.0', - dependencies: { - 'ember-cli-babel': '^7.26.11', - 'ember-cli-htmlbars': '^6.1.1', - }, - devDependencies: {}, - 'ember-addon': { - configPath: 'tests/dummy/config', - }, }, null, 2 ), - 'yarn.lock': 'some code for yarn.lock', + 'yarn.lock': '', }; loadFixture(inputProject, options); diff --git a/tests/migration/ember-addon/steps/augment-options/error-handling-package-version-is-missing.test.js b/tests/migration/ember-addon/steps/augment-options/error-handling-package-version-is-missing.test.js new file mode 100644 index 00000000..5eb0f82a --- /dev/null +++ b/tests/migration/ember-addon/steps/augment-options/error-handling-package-version-is-missing.test.js @@ -0,0 +1,38 @@ +import { augmentOptions } from '../../../../../src/migration/ember-addon/steps/augment-options.js'; +import { assert, loadFixture, test } from '../../../../test-helpers.js'; + +test('migration | ember-addon | steps | augment-options > error handling (package version is missing)', function () { + const options = { + addonLocation: undefined, + projectRoot: 'tmp/new-v1-addon-javascript', + testAppLocation: undefined, + testAppName: undefined, + }; + + const inputProject = { + 'package.json': JSON.stringify( + { + name: 'new-v1-addon', + }, + null, + 2 + ), + 'yarn.lock': '', + }; + + loadFixture(inputProject, options); + + assert.throws( + () => { + augmentOptions(options); + }, + (error) => { + assert.strictEqual( + error.message, + 'ERROR: In package.json, the package version is missing.' + ); + + return true; + } + ); +}); diff --git a/tests/migration/ember-addon/steps/augment-options/glint.test.js b/tests/migration/ember-addon/steps/augment-options/glint.test.js index 870c0169..9c40404a 100644 --- a/tests/migration/ember-addon/steps/augment-options/glint.test.js +++ b/tests/migration/ember-addon/steps/augment-options/glint.test.js @@ -29,7 +29,7 @@ test('migration | ember-addon | steps | augment-options > Glint', function () { null, 2 ), - 'yarn.lock': 'some code for yarn.lock', + 'yarn.lock': '', }; loadFixture(inputProject, options); diff --git a/tests/migration/ember-addon/steps/augment-options/javascript.test.js b/tests/migration/ember-addon/steps/augment-options/javascript.test.js index c50cf715..2e687f6f 100644 --- a/tests/migration/ember-addon/steps/augment-options/javascript.test.js +++ b/tests/migration/ember-addon/steps/augment-options/javascript.test.js @@ -26,7 +26,7 @@ test('migration | ember-addon | steps | augment-options > JavaScript', function null, 2 ), - 'yarn.lock': 'some code for yarn.lock', + 'yarn.lock': '', }; loadFixture(inputProject, options); diff --git a/tests/migration/ember-addon/steps/augment-options/npm.test.js b/tests/migration/ember-addon/steps/augment-options/npm.test.js index 5c847c69..147b6118 100644 --- a/tests/migration/ember-addon/steps/augment-options/npm.test.js +++ b/tests/migration/ember-addon/steps/augment-options/npm.test.js @@ -26,7 +26,7 @@ test('migration | ember-addon | steps | augment-options > npm', function () { null, 2 ), - 'package-lock.json': 'some code for package-lock.json', + 'package-lock.json': '', }; loadFixture(inputProject, options); diff --git a/tests/migration/ember-addon/steps/augment-options/pnpm.test.js b/tests/migration/ember-addon/steps/augment-options/pnpm.test.js index 385d8fbf..09be1058 100644 --- a/tests/migration/ember-addon/steps/augment-options/pnpm.test.js +++ b/tests/migration/ember-addon/steps/augment-options/pnpm.test.js @@ -26,7 +26,7 @@ test('migration | ember-addon | steps | augment-options > pnpm', function () { null, 2 ), - 'pnpm-lock.yaml': 'some code for pnpm-lock.yaml', + 'pnpm-lock.yaml': '', }; loadFixture(inputProject, options); diff --git a/tests/migration/ember-addon/steps/augment-options/scoped-package.test.js b/tests/migration/ember-addon/steps/augment-options/scoped-package.test.js index d21a139b..94ebc614 100644 --- a/tests/migration/ember-addon/steps/augment-options/scoped-package.test.js +++ b/tests/migration/ember-addon/steps/augment-options/scoped-package.test.js @@ -26,7 +26,7 @@ test('migration | ember-addon | steps | augment-options > scoped package', funct null, 2 ), - 'yarn.lock': 'some code for yarn.lock', + 'yarn.lock': '', }; loadFixture(inputProject, options); diff --git a/tests/migration/ember-addon/steps/augment-options/typescript.test.js b/tests/migration/ember-addon/steps/augment-options/typescript.test.js index f77e260a..c27d1dda 100644 --- a/tests/migration/ember-addon/steps/augment-options/typescript.test.js +++ b/tests/migration/ember-addon/steps/augment-options/typescript.test.js @@ -28,7 +28,7 @@ test('migration | ember-addon | steps | augment-options > TypeScript', function null, 2 ), - 'yarn.lock': 'some code for yarn.lock', + 'yarn.lock': '', }; loadFixture(inputProject, options); diff --git a/tests/migration/ember-addon/steps/augment-options/v2-addon.test.js b/tests/migration/ember-addon/steps/augment-options/v2-addon.test.js index 5edabacb..60533597 100644 --- a/tests/migration/ember-addon/steps/augment-options/v2-addon.test.js +++ b/tests/migration/ember-addon/steps/augment-options/v2-addon.test.js @@ -20,7 +20,7 @@ test('migration | ember-addon | steps | augment-options > v2 addon', function () null, 2 ), - 'yarn.lock': 'some code for yarn.lock', + 'yarn.lock': '', }; loadFixture(inputProject, options); From d1d3cdd8ad9878b48a174d17af67134d6a45f251 Mon Sep 17 00:00:00 2001 From: ijlee2 Date: Wed, 18 Jan 2023 09:04:31 +0100 Subject: [PATCH 3/6] refactor: Added tests for analyzeAddon --- .../steps/analyze-addon/base-case.test.js | 79 +++++++++++++++++++ .../edge-case-folders-are-missing.test.js | 30 +++++++ 2 files changed, 109 insertions(+) create mode 100644 tests/migration/ember-addon/steps/analyze-addon/base-case.test.js create mode 100644 tests/migration/ember-addon/steps/analyze-addon/edge-case-folders-are-missing.test.js diff --git a/tests/migration/ember-addon/steps/analyze-addon/base-case.test.js b/tests/migration/ember-addon/steps/analyze-addon/base-case.test.js new file mode 100644 index 00000000..eb70f3ff --- /dev/null +++ b/tests/migration/ember-addon/steps/analyze-addon/base-case.test.js @@ -0,0 +1,79 @@ +import { analyzeAddon } from '../../../../../src/migration/ember-addon/steps/analyze-addon.js'; +import { assert, loadFixture, test } from '../../../../test-helpers.js'; + +test('migration | ember-addon | steps | analyze-addon > base case', function () { + const options = { + addonLocation: undefined, + projectRoot: 'tmp/ember-container-query-typescript', + testAppLocation: undefined, + testAppName: undefined, + }; + + const inputProject = { + addon: { + components: { + 'container-query.hbs': '', + 'container-query.ts': '', + }, + helpers: { + 'aspect-ratio.ts': '', + 'height.ts': '', + 'width.ts': '', + }, + modifiers: { + 'container-query.ts': '', + }, + styles: { + 'container-query.css': '', + }, + '.gitkeep': '', + 'index.ts': '', + 'template-registry.ts': '', + }, + app: { + components: { + 'container-query.js': '', + }, + helpers: { + 'aspect-ratio.js': '', + 'height.js': '', + 'width.js': '', + }, + modifiers: { + 'container-query.js': '', + }, + '.gitkeep': '', + }, + }; + + const expectedValue = { + appReexports: [ + 'components/container-query.js', + 'helpers/aspect-ratio.js', + 'helpers/height.js', + 'helpers/width.js', + 'modifiers/container-query.js', + ], + publicEntrypoints: [ + 'components/container-query.js', + 'helpers/aspect-ratio.js', + 'helpers/height.js', + 'helpers/width.js', + 'index.js', + 'modifiers/container-query.js', + 'template-registry.js', + ], + }; + + loadFixture(inputProject, options); + + // Run the step + const augmentedOptions = { + projectRoot: 'tmp/ember-container-query-typescript', + }; + + assert.deepEqual(analyzeAddon(augmentedOptions), expectedValue); + + // Check idempotence + assert.deepEqual(analyzeAddon(augmentedOptions), expectedValue); +}); diff --git a/tests/migration/ember-addon/steps/analyze-addon/edge-case-folders-are-missing.test.js b/tests/migration/ember-addon/steps/analyze-addon/edge-case-folders-are-missing.test.js new file mode 100644 index 00000000..838d35b8 --- /dev/null +++ b/tests/migration/ember-addon/steps/analyze-addon/edge-case-folders-are-missing.test.js @@ -0,0 +1,30 @@ +import { analyzeAddon } from '../../../../../src/migration/ember-addon/steps/analyze-addon.js'; +import { assert, loadFixture, test } from '../../../../test-helpers.js'; + +test('migration | ember-addon | steps | analyze-addon > edge case (folders are missing)', function () { + const options = { + addonLocation: undefined, + projectRoot: 'tmp/new-v1-addon-javascript', + testAppLocation: undefined, + testAppName: undefined, + }; + + const inputProject = {}; + + const expectedValue = { + appReexports: [], + publicEntrypoints: [], + }; + + loadFixture(inputProject, options); + + // Run the step + const augmentedOptions = { + projectRoot: 'tmp/new-v1-addon-javascript', + }; + + assert.deepEqual(analyzeAddon(augmentedOptions), expectedValue); + + // Check idempotence + assert.deepEqual(analyzeAddon(augmentedOptions), expectedValue); +}); From c9ab055124fb83c4231802948c4a69e31cd417b5 Mon Sep 17 00:00:00 2001 From: ijlee2 Date: Wed, 18 Jan 2023 09:49:43 +0100 Subject: [PATCH 4/6] refactor: Added tests for useRelativePaths --- .../use-relative-paths/base-case.test.js | 163 ++++++++++++++++++ .../edge-case-folders-are-missing.test.js | 31 ++++ 2 files changed, 194 insertions(+) create mode 100644 tests/migration/ember-addon/steps/use-relative-paths/base-case.test.js create mode 100644 tests/migration/ember-addon/steps/use-relative-paths/edge-case-folders-are-missing.test.js diff --git a/tests/migration/ember-addon/steps/use-relative-paths/base-case.test.js b/tests/migration/ember-addon/steps/use-relative-paths/base-case.test.js new file mode 100644 index 00000000..7f405423 --- /dev/null +++ b/tests/migration/ember-addon/steps/use-relative-paths/base-case.test.js @@ -0,0 +1,163 @@ +import { useRelativePaths } from '../../../../../src/migration/ember-addon/steps/use-relative-paths.js'; +import { assertFixture, loadFixture, test } from '../../../../test-helpers.js'; + +const fileMapping = new Map([ + [ + 'addon/components/container-query.ts', + { + input: [ + `import { action } from '@ember/object';`, + `import Component from '@glimmer/component';`, + `import { tracked } from '@glimmer/tracking';`, + ``, + `import type {`, + ` Dimensions,`, + ` Features,`, + ` IndexSignatureParameter,`, + ` QueryResults,`, + `} from 'ember-container-query/modifiers/container-query';`, + ].join('\n'), + + output: [ + `import { action } from '@ember/object';`, + `import Component from '@glimmer/component';`, + `import { tracked } from '@glimmer/tracking';`, + ``, + `import type {`, + ` Dimensions,`, + ` Features,`, + ` IndexSignatureParameter,`, + ` QueryResults,`, + `} from '../modifiers/container-query';`, + ].join('\n'), + }, + ], + + [ + 'tests/dummy/app/components/widgets/widget-3/tour-schedule/responsive-image.ts', + { + input: [ + `import { action } from '@ember/object';`, + `import Component from '@glimmer/component';`, + `import { tracked } from '@glimmer/tracking';`, + `import type { Image } from 'dummy/data/concert';`, + `import { findBestFittingImage } from 'dummy/utils/components/widgets/widget-3';`, + `import type { Dimensions } from 'ember-container-query/modifiers/container-query';`, + ].join('\n'), + + output: [ + `import { action } from '@ember/object';`, + `import Component from '@glimmer/component';`, + `import { tracked } from '@glimmer/tracking';`, + `import type { Image } from '../../../../data/concert';`, + `import { findBestFittingImage } from '../../../../utils/components/widgets/widget-3';`, + `import type { Dimensions } from 'ember-container-query/modifiers/container-query';`, + ].join('\n'), + }, + ], + + [ + 'tests/dummy/app/app.ts', + { + input: [ + `import Application from '@ember/application';`, + `import config from 'dummy/config/environment';`, + `import loadInitializers from 'ember-load-initializers';`, + `import Resolver from 'ember-resolver';`, + ].join('\n'), + + output: [ + `import Application from '@ember/application';`, + `import config from './config/environment';`, + `import loadInitializers from 'ember-load-initializers';`, + `import Resolver from 'ember-resolver';`, + ].join('\n'), + }, + ], +]); + +test('migration | ember-addon | steps | use-relative-paths > base case', function () { + const options = { + addonLocation: undefined, + projectRoot: 'tmp/ember-container-query-typescript', + testAppLocation: undefined, + testAppName: undefined, + }; + + const inputProject = { + addon: { + components: { + 'container-query.ts': fileMapping.get( + 'addon/components/container-query.ts' + ).input, + }, + }, + tests: { + dummy: { + app: { + components: { + widgets: { + 'widget-3': { + 'tour-schedule': { + 'responsive-image.ts': fileMapping.get( + 'tests/dummy/app/components/widgets/widget-3/tour-schedule/responsive-image.ts' + ).input, + }, + }, + }, + }, + 'app.ts': fileMapping.get('tests/dummy/app/app.ts').input, + }, + }, + }, + }; + + const outputProject = { + addon: { + components: { + 'container-query.ts': fileMapping.get( + 'addon/components/container-query.ts' + ).output, + }, + }, + tests: { + dummy: { + app: { + components: { + widgets: { + 'widget-3': { + 'tour-schedule': { + 'responsive-image.ts': fileMapping.get( + 'tests/dummy/app/components/widgets/widget-3/tour-schedule/responsive-image.ts' + ).output, + }, + }, + }, + }, + 'app.ts': fileMapping.get('tests/dummy/app/app.ts').output, + }, + }, + }, + }; + + loadFixture(inputProject, options); + + // Run the step + const augmentedOptions = { + packages: { + addon: { + name: 'ember-container-query', + }, + }, + projectRoot: 'tmp/ember-container-query-typescript', + }; + + useRelativePaths(augmentedOptions); + + assertFixture(outputProject, options); + + // Check idempotence + useRelativePaths(augmentedOptions); + + assertFixture(outputProject, options); +}); diff --git a/tests/migration/ember-addon/steps/use-relative-paths/edge-case-folders-are-missing.test.js b/tests/migration/ember-addon/steps/use-relative-paths/edge-case-folders-are-missing.test.js new file mode 100644 index 00000000..605772a8 --- /dev/null +++ b/tests/migration/ember-addon/steps/use-relative-paths/edge-case-folders-are-missing.test.js @@ -0,0 +1,31 @@ +import { useRelativePaths } from '../../../../../src/migration/ember-addon/steps/use-relative-paths.js'; +import { assertFixture, loadFixture, test } from '../../../../test-helpers.js'; + +test('migration | ember-addon | steps | use-relative-paths > edge case (folders are missing)', function () { + const options = { + addonLocation: undefined, + projectRoot: 'tmp/new-v1-addon-javascript', + testAppLocation: undefined, + testAppName: undefined, + }; + + const inputProject = {}; + + const outputProject = {}; + + loadFixture(inputProject, options); + + // Run the step + const augmentedOptions = { + projectRoot: 'tmp/new-v1-addon-javascript', + }; + + useRelativePaths(augmentedOptions); + + assertFixture(outputProject, options); + + // Check idempotence + useRelativePaths(augmentedOptions); + + assertFixture(outputProject, options); +}); From e1beaac935e7af76ae5537ab5da11c03e4f025f8 Mon Sep 17 00:00:00 2001 From: ijlee2 Date: Wed, 18 Jan 2023 10:14:07 +0100 Subject: [PATCH 5/6] refactor: Removed unused code. Localized variables. --- .../steps/update-addon-package-json.js | 28 +++++++++---------- .../steps/update-test-app-package-json.js | 5 +++- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/migration/ember-addon/steps/update-addon-package-json.js b/src/migration/ember-addon/steps/update-addon-package-json.js index 53ddba25..0ee4e99a 100644 --- a/src/migration/ember-addon/steps/update-addon-package-json.js +++ b/src/migration/ember-addon/steps/update-addon-package-json.js @@ -17,12 +17,12 @@ function updateDependencies(packageJson) { 'ember-cli-htmlbars', ]; - const packagesToInstall = ['@embroider/addon-shim']; - packagesToDelete.forEach((packageName) => { dependencies.delete(packageName); }); + const packagesToInstall = ['@embroider/addon-shim']; + packagesToInstall.forEach((packageName) => { const version = decideVersion(packageName, dependencies); @@ -37,12 +37,17 @@ function updateDevDependencies(packageJson, options) { const devDependencies = convertToMap(packageJson['devDependencies']); - const packagesToDelete = [ - '@embroider/macros', - 'ember-auto-import', - 'ember-cli-babel', - 'ember-cli-htmlbars', - ]; + /* + For the time being, we'll take the approach of starting over and + adding back the development dependencies that are required. For + a more conservative approach, we could delete only the following: + + - @embroider/macros + - ember-auto-import + - ember-cli-babel + - ember-cli-htmlbars + */ + devDependencies.clear(); const packagesToInstall = packages.addon.hasTypeScript ? [ @@ -65,13 +70,6 @@ function updateDevDependencies(packageJson, options) { 'rollup-plugin-copy', ]; - // May be easier to start over and add missing dependencies - devDependencies.clear(); - - packagesToDelete.forEach((packageName) => { - devDependencies.delete(packageName); - }); - packagesToInstall.forEach((packageName) => { const version = decideVersion(packageName, devDependencies); diff --git a/src/migration/ember-addon/steps/update-test-app-package-json.js b/src/migration/ember-addon/steps/update-test-app-package-json.js index b88f6f4b..e42e0c51 100644 --- a/src/migration/ember-addon/steps/update-test-app-package-json.js +++ b/src/migration/ember-addon/steps/update-test-app-package-json.js @@ -37,7 +37,10 @@ function moveDependenciesToDevDependencies(packageJson, options) { function updateDependencies(packageJson) { const dependencies = convertToMap(packageJson['dependencies']); - // May be easier to start over and add missing dependencies + /* + For the time being, we'll take the approach of starting over and + adding back the dependencies that are required. + */ dependencies.clear(); packageJson['dependencies'] = convertToObject(dependencies); From 23c666a81ed9cbc06ea37552430d4e744246ec63 Mon Sep 17 00:00:00 2001 From: ijlee2 Date: Wed, 18 Jan 2023 10:15:53 +0100 Subject: [PATCH 6/6] bugfix: Provided the default value of [] to prevent a runtime error --- .../ember-addon/steps/update-test-app-package-json.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/migration/ember-addon/steps/update-test-app-package-json.js b/src/migration/ember-addon/steps/update-test-app-package-json.js index e42e0c51..00f3e727 100644 --- a/src/migration/ember-addon/steps/update-test-app-package-json.js +++ b/src/migration/ember-addon/steps/update-test-app-package-json.js @@ -61,9 +61,9 @@ function updateOtherFields(packageJson, options) { delete packageJson['ember-addon']; - packageJson['keywords'] = packageJson['keywords'].filter((keyword) => { - return keyword !== 'ember-addon'; - }); + packageJson['keywords'] = (packageJson['keywords'] ?? []).filter( + (keyword) => keyword !== 'ember-addon' + ); packageJson['name'] = packages.testApp.name;