Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into feature/GH-3075
Browse files Browse the repository at this point in the history
  • Loading branch information
dydome committed Jun 18, 2021
2 parents c79c3af + 8ce0047 commit c507f0c
Show file tree
Hide file tree
Showing 18 changed files with 149 additions and 27 deletions.
16 changes: 16 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,22 @@
"args": ["add", "@spartacus/schematics@latest"],
"console": "integratedTerminal",
"outFiles": ["${workspaceFolder}/**/*.js"]
},

// to debug a schematics Jest test, make sure that a spec.ts file is currently opened.
{
"type": "node",
"request": "launch",
"name": "Debug project/schematics Jest test",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"args": [
"${fileBasenameNoExtension}",
"--config",
"projects/schematics/jest.schematics.config.js"
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"disableOptimisticBPs": true
}
]
}
30 changes: 28 additions & 2 deletions docs/migration/4_0.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,14 +289,40 @@ Lib: @spartacus/core
Class: UserAddressService
Change: Two new required constructor parameters `userAddressConnector: UserAddressConnector` and `command: CommandService`
## New Checkout Library
Spartacus 4.0 introduces the checkout library. The checkout related code is moved out of `@spartacus/core` and `@spartacus/storefrontlib` into one of the checkout lib's entry points. The checkout library is split into these entry points:
```
@spartacus/checkout/assets
( checkout related i18n keys are moved here )

@spartacus/checkout/components
( checkout related UI codee is moved here. This includes components, guards and ui services )

@spartacus/checkout/core
The checkout facade API implementation are moved here, as well as connectors, event builder, event listener, models, other services, and state management.

@spartacus/checkout/occ
The checkout related OCC code is moved here. This includes the checkout related adapters and converters.

@spartacus/checkout/root
The root entry point is, by convention, meant to always be eager loaded. It contains the config, events, facades, http interceptors and models.

@spartacus/checkout/styles
The checkout related scss styles are moved here.

```
Most of the code is moved unchanged, but some classes required changes after they were moved. See the section below for the list:
## (start) Changes in the classes carried over to the @spartacus/checkout lib
### CheckoutEventModule
Class: CheckoutEventModule
Change: One new required constructor parameters `_checkoutEventListener: CheckoutEventListener`
### PaymentFormComponent
Class: PaymentFormComponent
Changes:
- PaymentFormComponent does not implement `OnDestroy` anymore
- method `ngOnDestroy()` removed.
Expand Down
2 changes: 1 addition & 1 deletion feature-libs/asm/jest.schematics.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = {
},
globals: {
'ts-jest': {
tsconfig: './tsconfig.schematics.json',
tsconfig: '<rootDir>/tsconfig.schematics.json',
},
},
collectCoverage: false,
Expand Down
2 changes: 1 addition & 1 deletion feature-libs/cart/jest.schematics.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = {
},
globals: {
'ts-jest': {
tsconfig: './tsconfig.schematics.json',
tsconfig: '<rootDir>/tsconfig.schematics.json',
},
},
collectCoverage: false,
Expand Down
2 changes: 1 addition & 1 deletion feature-libs/checkout/jest.schematics.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = {
},
globals: {
'ts-jest': {
tsconfig: './tsconfig.schematics.json',
tsconfig: '<rootDir>/tsconfig.schematics.json',
},
},
collectCoverage: false,
Expand Down
2 changes: 1 addition & 1 deletion feature-libs/organization/jest.schematics.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = {
},
globals: {
'ts-jest': {
tsconfig: './tsconfig.schematics.json',
tsconfig: '<rootDir>/tsconfig.schematics.json',
},
},
collectCoverage: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = {
},
globals: {
'ts-jest': {
tsconfig: './tsconfig.schematics.json',
tsconfig: '<rootDir>/tsconfig.schematics.json',
},
},

Expand Down
2 changes: 1 addition & 1 deletion feature-libs/product/jest.schematics.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = {
},
globals: {
'ts-jest': {
tsconfig: './tsconfig.schematics.json',
tsconfig: '<rootDir>/tsconfig.schematics.json',
},
},
collectCoverage: false,
Expand Down
2 changes: 1 addition & 1 deletion feature-libs/qualtrics/jest.schematics.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = {
},
globals: {
'ts-jest': {
tsconfig: './tsconfig.schematics.json',
tsconfig: '<rootDir>/tsconfig.schematics.json',
},
},
collectCoverage: false,
Expand Down
2 changes: 1 addition & 1 deletion feature-libs/smartedit/jest.schematics.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = {
},
globals: {
'ts-jest': {
tsconfig: './tsconfig.schematics.json',
tsconfig: '<rootDir>/tsconfig.schematics.json',
},
},
collectCoverage: false,
Expand Down
2 changes: 1 addition & 1 deletion feature-libs/storefinder/jest.schematics.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = {
},
globals: {
'ts-jest': {
tsconfig: './tsconfig.schematics.json',
tsconfig: '<rootDir>/tsconfig.schematics.json',
},
},
collectCoverage: false,
Expand Down
2 changes: 1 addition & 1 deletion feature-libs/tracking/jest.schematics.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = {
},
globals: {
'ts-jest': {
tsconfig: './tsconfig.schematics.json',
tsconfig: '<rootDir>/tsconfig.schematics.json',
},
},
collectCoverage: false,
Expand Down
2 changes: 1 addition & 1 deletion feature-libs/user/jest.schematics.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = {
},
globals: {
'ts-jest': {
tsconfig: './tsconfig.schematics.json',
tsconfig: '<rootDir>/tsconfig.schematics.json',
},
},
collectCoverage: false,
Expand Down
2 changes: 1 addition & 1 deletion integration-libs/cdc/jest.schematics.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = {
},
globals: {
'ts-jest': {
tsconfig: './tsconfig.schematics.json',
tsconfig: '<rootDir>/tsconfig.schematics.json',
},
},
collectCoverage: false,
Expand Down
2 changes: 1 addition & 1 deletion integration-libs/cds/jest.schematics.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = {
},
globals: {
'ts-jest': {
tsconfig: './tsconfig.schematics.json',
tsconfig: '<rootDir>/tsconfig.schematics.json',
},
},
collectCoverage: false,
Expand Down
2 changes: 1 addition & 1 deletion projects/schematics/jest.schematics.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = {
},
globals: {
'ts-jest': {
tsconfig: './tsconfig.schematics.json',
tsconfig: '<rootDir>/tsconfig.schematics.json',
}
},
collectCoverage: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import {
installPackageJsonDependencies,
} from '../../../shared/utils/lib-utils';
import {
CORE_SPARTACUS_SCOPES,
createDependencies,
FEATURES_LIBS_SKIP_SCOPES,
readPackageJson,
} from '../../../shared/utils/package-utils';

Expand All @@ -24,16 +24,20 @@ export function migrateDependencies(
removedDependencies: string[]
): Rule {
const packageJson = readPackageJson(tree);
const installedSpartacusLibs = collectSpartacusLibraryDependencies(
packageJson
);
const {
spartacusPeerDeps,
installedLibs,
} = collectSpartacusLibraryDependencies(packageJson);
const allSpartacusDeps = installedLibs.concat(spartacusPeerDeps);

const dependencies = createSpartacusLibraryDependencies(
installedSpartacusLibs
allSpartacusDeps,
installedLibs
);

checkAndLogRemovedDependencies(
packageJson,
installedSpartacusLibs,
allSpartacusDeps,
removedDependencies,
context.logger
);
Expand All @@ -44,26 +48,70 @@ export function migrateDependencies(
]);
}

function collectSpartacusLibraryDependencies(packageJson: any): string[] {
function collectSpartacusLibraryDependencies(
packageJson: any
): { installedLibs: string[]; spartacusPeerDeps: string[] } {
const dependencies =
(packageJson.dependencies as Record<string, string>) ?? {};
return Object.keys(dependencies).filter((d) => d.startsWith(SPARTACUS_SCOPE));
const installedLibs = Object.keys(dependencies).filter((dep) =>
dep.startsWith(SPARTACUS_SCOPE)
);
const nonCoreLibs = installedLibs.filter(
(lib) => !CORE_SPARTACUS_SCOPES.includes(lib)
);

let spartacusPeerDeps: string[] = [];
for (const spartacusLib of nonCoreLibs) {
spartacusPeerDeps = collectSpartacusPeerDeps(
spartacusPeerDeps,
spartacusLib
);
}

// remove the duplicates
spartacusPeerDeps = Array.from(new Set<string>(spartacusPeerDeps));
return {
installedLibs,
spartacusPeerDeps,
};
}

function collectSpartacusPeerDeps(
collectedDeps: string[],
name: string
): string[] {
const peerDepsWithVersions = (collectedDependencies as Record<
string,
Record<string, string>
>)[name];
const peerDeps = Object.keys(peerDepsWithVersions)
.filter((d) => d.startsWith(SPARTACUS_SCOPE))
.filter((d) => !CORE_SPARTACUS_SCOPES.includes(d))
.filter((d) => !collectedDeps.includes(d));

collectedDeps = collectedDeps.concat(peerDeps);
for (const peerDep of peerDeps) {
collectedDeps = collectSpartacusPeerDeps(collectedDeps, peerDep);
}

return collectedDeps;
}

function createSpartacusLibraryDependencies(
installedSpartacusLibs: string[]
allSpartacusLibraries: string[],
skipScopes: string[]
): NodeDependency[] {
const dependenciesToAdd: NodeDependency[] = [];

for (const libraryName of installedSpartacusLibs) {
for (const libraryName of allSpartacusLibraries) {
const spartacusLibrary = (collectedDependencies as Record<
string,
Record<string, string>
>)[libraryName];

dependenciesToAdd.push(
...createDependencies(spartacusLibrary, {
skipScopes: FEATURES_LIBS_SKIP_SCOPES,
skipScopes,
overwrite: true,
})
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,36 @@ describe('dependency management migrations', () => {
);
});
});

describe('cross dependencies', () => {
beforeEach(() => {
writeFile(
host,
'/package.json',
JSON.stringify({
name: 'xxx',
version: '3.0.0',
dependencies: {
'@spartacus/core': '3.0.0',
'@spartacus/storefront': '3.0.0',
'@spartacus/cds': '3.0.0',
'@spartacus/qualtrics': '3.0.0',
},
})
);
});
it('should install cross spartacus peer deps', async () => {
await runMigration(appTree, schematicRunner, MIGRATION_SCRIPT_NAME);

const packageJson = JSON.parse(appTree.readContent('/package.json'));

expect(packageJson.dependencies['@spartacus/core']).toBeTruthy();
expect(packageJson.dependencies['@spartacus/storefront']).toBeTruthy();
expect(packageJson.dependencies['@spartacus/cds']).toBeTruthy();
expect(packageJson.dependencies['@spartacus/tracking']).toBeTruthy();
expect(packageJson.dependencies['@spartacus/cart']).toBeTruthy();
expect(packageJson.dependencies['@spartacus/checkout']).toBeTruthy();
expect(packageJson.dependencies['@spartacus/qualtrics']).toBeTruthy();
});
});
});

0 comments on commit c507f0c

Please sign in to comment.