Skip to content

Commit 5a4b5e4

Browse files
Fix tests
1 parent e2a2fcb commit 5a4b5e4

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

ern-composite-gen/src/createBabelRc.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import fs from 'fs-extra';
22
import path from 'path';
3-
import { v4 as uuid } from 'uuid';
3+
import { v4 as uuid, validate as uuidValidate } from 'uuid';
44
import semver from 'semver';
55
import { log, readPackageJson, writePackageJson } from 'ern-core';
66
import { getNodeModuleVersion } from './getNodeModuleVersion';
@@ -56,7 +56,11 @@ export async function createBabelRc({
5656
// it messing with other module-resolver plugin configurations that could
5757
// be defined in the .babelrc config of individual MiniApps
5858
// https://babeljs.io/docs/en/options#plugin-preset-merging
59-
babelPlugin.push(uuid());
59+
// Check if lastItem of babel plugin is not uuid
60+
const lastItem = babelPlugin.slice(-1)[0];
61+
if (typeof lastItem !== "string" || !uuidValidate(lastItem)) {
62+
babelPlugin.push(uuid());
63+
}
6064
// Copy over module-resolver plugin & config to top level composite .babelrc
6165
log.debug(
6266
`Taking care of module-resolver Babel plugin for ${miniAppName} MiniApp`,
@@ -68,6 +72,10 @@ export async function createBabelRc({
6872
for (const x of babelPlugin) {
6973
if (x instanceof Object && x.alias) {
7074
moduleResolverAliases = x.alias;
75+
Object.keys(moduleResolverAliases).map((key) => {
76+
if (!moduleResolverAliases[key].startsWith(miniAppName))
77+
moduleResolverAliases[key] = `${miniAppName}/${moduleResolverAliases[key].replace('./', '')}`;
78+
})
7179
break;
7280
}
7381
}
@@ -105,7 +113,6 @@ export async function createBabelRc({
105113
log.debug(
106114
`Removing babel object from ${miniAppName} MiniApp package.json`,
107115
);
108-
delete miniAppPackageJson.babel;
109116
await writePackageJson(p, miniAppPackageJson);
110117
}
111118
}

ern-composite-gen/test/compositegen-test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ describe('ern-container-gen utils.js', () => {
368368
pathToYarnLock: pathToSampleYarnLock,
369369
});
370370
assert(yarnCliStub.install.calledOnce);
371-
sinon.assert.callCount(yarnCliStub.add, 4);
371+
sinon.assert.callCount(yarnCliStub.add, 5);
372372
assert(yarnCliStub.install.calledBefore(yarnCliStub.add));
373373
});
374374

@@ -408,7 +408,7 @@ describe('ern-container-gen utils.js', () => {
408408
];
409409
yarnCliStub.init.callsFake(() => fakeYarnInit(tmpOutDir, '0.57.0'));
410410
await generateComposite({ miniApps, outDir: tmpOutDir });
411-
sinon.assert.callCount(yarnCliStub.add, 5);
411+
sinon.assert.callCount(yarnCliStub.add, 6);
412412
});
413413

414414
it('should create index.js', async () => {

0 commit comments

Comments
 (0)