Skip to content

Commit

Permalink
Move skuba diving to appropriate step (#79)
Browse files Browse the repository at this point in the history
This migrates the last of the dependency logic out of the "config" step
into the earlier "dependency" step, so the dependency diff should be
fully accurate now.

This only implements a simple switch of "package means no dive,
application means dive". We can build on this to allow applications to
opt-out, as described in #26.
  • Loading branch information
72636c authored Jun 23, 2020
1 parent 23d4e09 commit 1fbb097
Show file tree
Hide file tree
Showing 15 changed files with 130 additions and 86 deletions.
5 changes: 5 additions & 0 deletions .changeset/plenty-garlics-refuse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'skuba': patch
---

**configure:** Handle `skuba-dive` dependency upfront
4 changes: 4 additions & 0 deletions src/cli/configure/analyseDependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { NormalizedReadResult } from 'read-pkg-up';

import { TextProcessor, copyFiles } from '../../utils/copy';
import { log } from '../../utils/logging';
import { ProjectType } from '../../utils/manifest';
import { getSkubaVersion } from '../../utils/version';

import { diffDependencies, generateNotices } from './analysis/package';
Expand Down Expand Up @@ -55,12 +56,14 @@ interface Props {
destinationRoot: string;
include: (pathname: string) => boolean;
manifest: NormalizedReadResult;
type: ProjectType;
}

export const analyseDependencies = async ({
destinationRoot,
include,
manifest: { packageJson },
type,
}: Props): Promise<undefined | (() => Promise<void>)> => {
const input = {
dependencies: packageJson.dependencies ?? {},
Expand All @@ -70,6 +73,7 @@ export const analyseDependencies = async ({
const output = {
dependencies: { ...input.dependencies },
devDependencies: { ...input.devDependencies },
type,
};

const printNotices = generateNotices(input);
Expand Down
3 changes: 0 additions & 3 deletions src/cli/configure/analysis/__snapshots__/project.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,6 @@ module.exports = {
},
"package.json": Object {
"data": "{
\\"dependencies\\": {
\\"skuba-dive\\": \\"0.0.1\\"
},
\\"license\\": \\"UNLICENSED\\",
\\"private\\": true,
\\"scripts\\": {
Expand Down
5 changes: 0 additions & 5 deletions src/cli/configure/analysis/project.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ import { defaultOpts } from '../testing/module';
import * as project from './project';
import { diffFiles } from './project';

jest.mock('latest-version', () => ({
__esModule: true,
default: () => Promise.resolve('0.0.1'),
}));

describe('diffFiles', () => {
it('works from scratch', async () => {
jest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe('seekDatadogCustomMetrics', () => {
devDependencies: {
'seek-datadog-custom-metrics': '1.0.0',
},
type: 'application' as const,
};

const result = seekDatadogCustomMetrics(input);
Expand All @@ -21,6 +22,7 @@ describe('seekDatadogCustomMetrics', () => {
devDependencies: {
'seek-datadog-custom-metrics': '1.0.0',
},
type: 'application',
});
});

Expand All @@ -32,6 +34,7 @@ describe('seekDatadogCustomMetrics', () => {
devDependencies: {
'@seek/node-datadog-custom-metrics': '1.0.0',
},
type: 'application' as const,
};

const result = seekDatadogCustomMetrics(input);
Expand All @@ -44,6 +47,7 @@ describe('seekDatadogCustomMetrics', () => {
devDependencies: {
'seek-datadog-custom-metrics': '*',
},
type: 'application',
});
});
});
4 changes: 4 additions & 0 deletions src/cli/configure/dependencies/seekKoala.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe('seekKoala', () => {
devDependencies: {
'seek-koala': '1.0.0',
},
type: 'application' as const,
};

const result = seekKoala(input);
Expand All @@ -21,6 +22,7 @@ describe('seekKoala', () => {
devDependencies: {
'seek-koala': '1.0.0',
},
type: 'application',
});
});

Expand All @@ -32,6 +34,7 @@ describe('seekKoala', () => {
devDependencies: {
'@seek/koala': '1.0.0',
},
type: 'application' as const,
};

const result = seekKoala(input);
Expand All @@ -44,6 +47,7 @@ describe('seekKoala', () => {
devDependencies: {
'seek-koala': '*',
},
type: 'application',
});
});
});
2 changes: 1 addition & 1 deletion src/cli/configure/dependencies/skuba.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('skuba', () => {
true,
],
])('%s', (_, input, expectReplacement = false) => {
const result = skuba(input);
const result = skuba({ ...input, type: 'application' });

expect(result).toHaveLength(expectReplacement ? 1 : 0);
expect(input).toEqual({
Expand Down
2 changes: 2 additions & 0 deletions src/cli/configure/dependencies/skubaDeps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ describe('skubaDeps', () => {
'pino-pretty': '0.0.1',
typescript: '0.0.1',
},
type: 'application' as const,
};

const result = skubaDeps(input);
Expand All @@ -23,6 +24,7 @@ describe('skubaDeps', () => {
devDependencies: {
'pino-pretty': '0.0.1',
},
type: 'application',
});
});
});
37 changes: 37 additions & 0 deletions src/cli/configure/dependencies/skubaDive.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ describe('skubaDive', () => {
'skuba-dive': '1.0.0',
},
devDependencies: {},
type: 'application' as const,
};

const result = skubaDive(input);
Expand All @@ -17,6 +18,7 @@ describe('skubaDive', () => {
'skuba-dive': '1.0.0',
},
devDependencies: {},
type: 'application',
});
});

Expand All @@ -26,6 +28,7 @@ describe('skubaDive', () => {
devDependencies: {
'skuba-dive': '1.0.0',
},
type: 'application' as const,
};

const result = skubaDive(input);
Expand All @@ -36,6 +39,7 @@ describe('skubaDive', () => {
'skuba-dive': '1.0.0',
},
devDependencies: {},
type: 'application',
});
});

Expand All @@ -47,6 +51,7 @@ describe('skubaDive', () => {
devDependencies: {
'@seek/skuba-dive': '1.0.0',
},
type: 'application' as const,
};

const result = skubaDive(input);
Expand All @@ -57,6 +62,38 @@ describe('skubaDive', () => {
'skuba-dive': '*',
},
devDependencies: {},
type: 'application',
});
});

it('strips many things from packages', () => {
const input = {
dependencies: {
'skuba-dive': '1.0.0',
'@seek/skuba-dive': '1.0.0',
lodash: '1.0.0',
'module-alias': '1.0.0',
},
devDependencies: {
'source-map-support': '1.0.0',
'skuba-dive': '1.0.0',
'@seek/skuba-dive': '1.0.0',
nock: '1.0.0',
},
type: 'package' as const,
};

const result = skubaDive(input);

expect(result).toHaveLength(0);
expect(input).toEqual({
dependencies: {
lodash: '1.0.0',
},
devDependencies: {
nock: '1.0.0',
},
type: 'package',
});
});
});
34 changes: 22 additions & 12 deletions src/cli/configure/dependencies/skubaDive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,32 @@ import { DependencySet } from '../types';
const OLD_NAME = '@seek/skuba-dive';
const NEW_NAME = 'skuba-dive';

export const skubaDive = ({ dependencies, devDependencies }: DependencySet) => {
// lazily upgrade to latest version of the new package
if (dependencies[OLD_NAME]) {
dependencies[NEW_NAME] = '*';
}
if (devDependencies[OLD_NAME]) {
devDependencies[NEW_NAME] = '*';
}
export const SKUBA_DIVE_HOOKS = ['module-alias', 'source-map-support'] as const;

export const skubaDive = ({
dependencies,
devDependencies,
type,
}: DependencySet) => {
SKUBA_DIVE_HOOKS.forEach((hook) => {
delete dependencies[hook];
delete devDependencies[hook];
});

// ensure dependency
if (devDependencies[NEW_NAME]) {
dependencies[NEW_NAME] =
dependencies[NEW_NAME] || devDependencies[NEW_NAME];
// skuba-dive is a runtime component; it's not appropriate for packages
if (type === 'package') {
delete dependencies[NEW_NAME];
delete devDependencies[NEW_NAME];
delete dependencies[OLD_NAME];
delete devDependencies[OLD_NAME];

return [];
}

dependencies[NEW_NAME] =
dependencies[NEW_NAME] || devDependencies[NEW_NAME] || '*';
delete devDependencies[NEW_NAME];

if (!dependencies[OLD_NAME] && !devDependencies[OLD_NAME]) {
return [];
}
Expand Down
5 changes: 4 additions & 1 deletion src/cli/configure/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export const configure = async () => {
destinationRoot,
include,
manifest,
type,
});

if (fixDependencies) {
Expand All @@ -95,9 +96,11 @@ export const configure = async () => {
}
}

if (fixConfiguration || fixDependencies) {
if (fixDependencies) {
await exec('yarn', 'install', '--silent');
}

if (fixConfiguration || fixDependencies) {
log.newline();
log.ok(`Try running ${log.bold('skuba format')}.`);
}
Expand Down
3 changes: 0 additions & 3 deletions src/cli/configure/modules/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ export const packageModule = async ({
};

const recurringData = {
devDependencies: {
skuba: version,
},
skuba: {
entryPoint,
type,
Expand Down
Loading

0 comments on commit 1fbb097

Please sign in to comment.