@servicetitan/startup 39.1.0 → 39.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/commands/mfe-list.d.ts +0 -2
- package/dist/cli/commands/mfe-list.d.ts.map +1 -1
- package/dist/cli/commands/mfe-list.js +4 -30
- package/dist/cli/commands/mfe-list.js.map +1 -1
- package/dist/cli/commands/mfe-package-clean.js +1 -2
- package/dist/cli/commands/mfe-package-clean.js.map +1 -1
- package/dist/cli/commands/mfe-package-publish.d.ts.map +1 -1
- package/dist/cli/commands/mfe-package-publish.js +7 -5
- package/dist/cli/commands/mfe-package-publish.js.map +1 -1
- package/dist/cli/commands/mfe-package-rollback.d.ts.map +1 -1
- package/dist/cli/commands/mfe-package-rollback.js +5 -3
- package/dist/cli/commands/mfe-package-rollback.js.map +1 -1
- package/dist/cli/commands/mfe-publish.d.ts +1 -0
- package/dist/cli/commands/mfe-publish.d.ts.map +1 -1
- package/dist/cli/commands/mfe-publish.js +14 -12
- package/dist/cli/commands/mfe-publish.js.map +1 -1
- package/dist/cli/commands/registry/command-registry.d.ts +13 -4
- package/dist/cli/commands/registry/command-registry.d.ts.map +1 -1
- package/dist/cli/commands/registry/mfe-list.d.ts +2 -1
- package/dist/cli/commands/registry/mfe-list.d.ts.map +1 -1
- package/dist/cli/commands/registry/mfe-list.js +3 -1
- package/dist/cli/commands/registry/mfe-list.js.map +1 -1
- package/dist/cli/commands/registry/mfe-package-clean.d.ts +2 -1
- package/dist/cli/commands/registry/mfe-package-clean.d.ts.map +1 -1
- package/dist/cli/commands/registry/mfe-package-clean.js +4 -2
- package/dist/cli/commands/registry/mfe-package-clean.js.map +1 -1
- package/dist/cli/commands/registry/mfe-package-publish.d.ts +2 -1
- package/dist/cli/commands/registry/mfe-package-publish.d.ts.map +1 -1
- package/dist/cli/commands/registry/mfe-package-publish.js +4 -2
- package/dist/cli/commands/registry/mfe-package-publish.js.map +1 -1
- package/dist/cli/commands/registry/mfe-package-rollback.d.ts +2 -1
- package/dist/cli/commands/registry/mfe-package-rollback.d.ts.map +1 -1
- package/dist/cli/commands/registry/mfe-package-rollback.js +4 -2
- package/dist/cli/commands/registry/mfe-package-rollback.js.map +1 -1
- package/dist/cli/commands/registry/upload-sourcemaps.d.ts +5 -0
- package/dist/cli/commands/registry/upload-sourcemaps.d.ts.map +1 -1
- package/dist/cli/commands/registry/upload-sourcemaps.js +5 -0
- package/dist/cli/commands/registry/upload-sourcemaps.js.map +1 -1
- package/dist/cli/commands/review/types.js.map +1 -1
- package/dist/cli/commands/upload-sourcemaps.d.ts.map +1 -1
- package/dist/cli/commands/upload-sourcemaps.js +4 -7
- package/dist/cli/commands/upload-sourcemaps.js.map +1 -1
- package/dist/cli/commands/utils/get-mfe-registry.d.ts +4 -0
- package/dist/cli/commands/utils/get-mfe-registry.d.ts.map +1 -0
- package/dist/cli/commands/utils/get-mfe-registry.js +28 -0
- package/dist/cli/commands/utils/get-mfe-registry.js.map +1 -0
- package/dist/cli/commands/utils/get-unpkg-host.d.ts +2 -0
- package/dist/cli/commands/utils/get-unpkg-host.d.ts.map +1 -0
- package/dist/cli/commands/utils/get-unpkg-host.js +18 -0
- package/dist/cli/commands/utils/get-unpkg-host.js.map +1 -0
- package/dist/cli/commands/utils/index.d.ts +3 -1
- package/dist/cli/commands/utils/index.d.ts.map +1 -1
- package/dist/cli/commands/utils/index.js +3 -1
- package/dist/cli/commands/utils/index.js.map +1 -1
- package/dist/cli/commands/utils/login.d.ts +2 -0
- package/dist/cli/commands/utils/login.d.ts.map +1 -0
- package/dist/cli/commands/utils/login.js +56 -0
- package/dist/cli/commands/utils/login.js.map +1 -0
- package/dist/cli/commands/utils/purge-cache.d.ts.map +1 -1
- package/dist/cli/commands/utils/purge-cache.js +2 -4
- package/dist/cli/commands/utils/purge-cache.js.map +1 -1
- package/dist/cli/index.js +4 -1
- package/dist/cli/index.js.map +1 -1
- package/dist/vite/config/base-config.js +1 -1
- package/dist/vite/config/base-config.js.map +1 -1
- package/dist/vite/config/create-resolve-config.d.ts +1 -2
- package/dist/vite/config/create-resolve-config.d.ts.map +1 -1
- package/dist/vite/config/create-resolve-config.js +2 -21
- package/dist/vite/config/create-resolve-config.js.map +1 -1
- package/package.json +21 -22
- package/src/cli/commands/__tests__/mfe-list.test.ts +25 -56
- package/src/cli/commands/__tests__/mfe-package-clean.test.ts +6 -0
- package/src/cli/commands/__tests__/mfe-package-publish.test.ts +52 -47
- package/src/cli/commands/__tests__/mfe-package-rollback.test.ts +4 -2
- package/src/cli/commands/__tests__/mfe-publish.test.ts +51 -14
- package/src/cli/commands/__tests__/upload-sourcemaps.test.ts +27 -13
- package/src/cli/commands/mfe-list.ts +7 -36
- package/src/cli/commands/mfe-package-clean.ts +2 -2
- package/src/cli/commands/mfe-package-publish.ts +10 -8
- package/src/cli/commands/mfe-package-rollback.ts +6 -5
- package/src/cli/commands/mfe-publish.ts +17 -16
- package/src/cli/commands/registry/mfe-list.ts +6 -1
- package/src/cli/commands/registry/mfe-package-clean.ts +7 -1
- package/src/cli/commands/registry/mfe-package-publish.ts +7 -1
- package/src/cli/commands/registry/mfe-package-rollback.ts +4 -2
- package/src/cli/commands/registry/upload-sourcemaps.ts +1 -0
- package/src/cli/commands/upload-sourcemaps.ts +4 -7
- package/src/cli/commands/utils/__tests__/get-mfe-registry.test.ts +24 -0
- package/src/cli/commands/utils/__tests__/get-unpkg-host.test.ts +32 -0
- package/src/cli/commands/utils/__tests__/login.test.ts +122 -0
- package/src/cli/commands/utils/__tests__/purge-cache.test.ts +17 -15
- package/src/cli/commands/utils/get-mfe-registry.ts +6 -0
- package/src/cli/commands/utils/get-unpkg-host.ts +8 -0
- package/src/cli/commands/utils/index.ts +3 -1
- package/src/cli/commands/utils/login.ts +38 -0
- package/src/cli/commands/utils/purge-cache.ts +2 -5
- package/src/cli/index.ts +2 -1
- package/src/vite/config/__tests__/create-resolve-config.test.ts +6 -37
- package/src/vite/config/base-config.ts +1 -1
- package/src/vite/config/create-resolve-config.ts +8 -22
- package/dist/cli/commands/utils/constants.d.ts +0 -2
- package/dist/cli/commands/utils/constants.d.ts.map +0 -1
- package/dist/cli/commands/utils/constants.js +0 -13
- package/dist/cli/commands/utils/constants.js.map +0 -1
- package/src/cli/commands/utils/constants.ts +0 -1
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { npmWhoAmI } from '@servicetitan/install';
|
|
2
|
+
import { createInterface } from 'readline/promises';
|
|
3
|
+
import { isTTY, runCommand } from '../../../utils';
|
|
4
|
+
import { DEV_MFE_REGISTRY, PROD_MFE_REGISTRY } from '../get-mfe-registry';
|
|
5
|
+
import { login } from '../login';
|
|
6
|
+
|
|
7
|
+
jest.mock('@servicetitan/install');
|
|
8
|
+
jest.mock('readline/promises', () => ({ createInterface: jest.fn() }));
|
|
9
|
+
jest.mock('../../../utils', () => ({
|
|
10
|
+
...jest.requireActual('../../../utils'),
|
|
11
|
+
isTTY: jest.fn(),
|
|
12
|
+
runCommand: jest.fn(),
|
|
13
|
+
}));
|
|
14
|
+
|
|
15
|
+
describe(`[startup] ${login.name}`, () => {
|
|
16
|
+
const readline = { question: jest.fn(), close: jest.fn() };
|
|
17
|
+
let answer: string;
|
|
18
|
+
let registry: string;
|
|
19
|
+
let user: string | undefined;
|
|
20
|
+
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
jest.clearAllMocks();
|
|
23
|
+
answer = 'Y';
|
|
24
|
+
registry = PROD_MFE_REGISTRY;
|
|
25
|
+
user = undefined;
|
|
26
|
+
jest.mocked(readline.question).mockImplementation(() => Promise.resolve(answer));
|
|
27
|
+
jest.mocked(createInterface).mockReturnValue(readline as any);
|
|
28
|
+
jest.mocked(npmWhoAmI).mockImplementation(() => user);
|
|
29
|
+
jest.mocked(isTTY).mockReturnValue(true);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const subject = () => login(registry);
|
|
33
|
+
|
|
34
|
+
test('prompts to authorize the machine', async () => {
|
|
35
|
+
await subject();
|
|
36
|
+
|
|
37
|
+
expect(readline.question).toHaveBeenCalledWith(
|
|
38
|
+
expect.stringMatching(/machine is not authorized.*Authorize\? \[Y\/n\]/)
|
|
39
|
+
);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test('closes the prompt', async () => {
|
|
43
|
+
await subject();
|
|
44
|
+
|
|
45
|
+
expect(readline.close).toHaveBeenCalled();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
function itAuthorizesTheMachine() {
|
|
49
|
+
test('authorizes the machine against the registry', async () => {
|
|
50
|
+
await subject();
|
|
51
|
+
|
|
52
|
+
expect(runCommand).toHaveBeenCalledWith(
|
|
53
|
+
`npx --yes verdaccio-okta-oauth@latest --registry=${registry}`,
|
|
54
|
+
{ quiet: true }
|
|
55
|
+
);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
itAuthorizesTheMachine();
|
|
60
|
+
|
|
61
|
+
describe('when user does not answer', () => {
|
|
62
|
+
beforeEach(() => (answer = ''));
|
|
63
|
+
|
|
64
|
+
itAuthorizesTheMachine();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
describe('when user declines', () => {
|
|
68
|
+
beforeEach(() => (answer = 'n'));
|
|
69
|
+
|
|
70
|
+
test('throws error', async () => {
|
|
71
|
+
await expect(subject()).rejects.toThrow(/Not authorized/);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
describe('when terminal is not interactive', () => {
|
|
76
|
+
beforeEach(() => jest.mocked(isTTY).mockReturnValue(false));
|
|
77
|
+
|
|
78
|
+
test('throws error', async () => {
|
|
79
|
+
await expect(subject()).rejects.toThrow(/machine is not authorized/);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
function itSkipsPrompt() {
|
|
84
|
+
test('skips the prompt', async () => {
|
|
85
|
+
await subject();
|
|
86
|
+
|
|
87
|
+
expect(readline.question).not.toHaveBeenCalled();
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
describe('when machine is already authorized', () => {
|
|
92
|
+
beforeEach(() => (user = 'someone'));
|
|
93
|
+
|
|
94
|
+
itSkipsPrompt();
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
describe(`when the registry is ${DEV_MFE_REGISTRY}`, () => {
|
|
98
|
+
beforeEach(() => (registry = DEV_MFE_REGISTRY));
|
|
99
|
+
|
|
100
|
+
itAuthorizesTheMachine();
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
describe('with an unrecognized registry', () => {
|
|
104
|
+
beforeEach(() => (registry = 'https://foo.com'));
|
|
105
|
+
|
|
106
|
+
test('throws error', async () => {
|
|
107
|
+
await expect(subject()).rejects.toThrow(/is not recognized/);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test('does not attempt oauth', async () => {
|
|
111
|
+
await expect(subject()).rejects.toThrow();
|
|
112
|
+
|
|
113
|
+
expect(runCommand).not.toHaveBeenCalled();
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
describe('when machine is already authorized', () => {
|
|
117
|
+
beforeEach(() => (user = 'someone'));
|
|
118
|
+
|
|
119
|
+
itSkipsPrompt();
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
});
|
|
@@ -1,40 +1,42 @@
|
|
|
1
1
|
import { runCommandOutput } from '../../../utils';
|
|
2
|
+
import { getUnpkgHost } from '../get-unpkg-host';
|
|
2
3
|
import { purgeCache } from '../purge-cache';
|
|
3
4
|
|
|
5
|
+
jest.mock('@servicetitan/install', () => ({ isCI: jest.fn() }));
|
|
4
6
|
jest.mock('../../../utils', () => ({
|
|
5
7
|
...jest.requireActual('../../../utils'),
|
|
6
8
|
runCommandOutput: jest.fn(),
|
|
7
9
|
}));
|
|
10
|
+
jest.mock('../get-unpkg-host', () => ({
|
|
11
|
+
getUnpkgHost: jest.fn(),
|
|
12
|
+
}));
|
|
8
13
|
|
|
9
14
|
describe(purgeCache.name, () => {
|
|
10
|
-
|
|
15
|
+
const unpkgHost = 'https://foo.com';
|
|
11
16
|
const packageName = '@servicetitan/foo';
|
|
17
|
+
const registry = 'https://bar.com';
|
|
12
18
|
const tag = 'prod';
|
|
19
|
+
let args: Parameters<typeof purgeCache>[0];
|
|
13
20
|
|
|
14
21
|
beforeEach(() => {
|
|
15
22
|
jest.clearAllMocks();
|
|
16
|
-
|
|
23
|
+
jest.mocked(getUnpkgHost).mockReturnValue(unpkgHost);
|
|
24
|
+
args = { packageName, registry, tag };
|
|
17
25
|
});
|
|
18
26
|
|
|
19
27
|
const subject = () => purgeCache(args);
|
|
20
28
|
|
|
21
|
-
test('
|
|
29
|
+
test('fetches host for registry', () => {
|
|
22
30
|
subject();
|
|
23
31
|
|
|
24
|
-
expect(
|
|
25
|
-
`npx startup mfe-purge-cache --host https://unpkg.servicetitan.com --package-name ${packageName} --tag ${tag}`
|
|
26
|
-
);
|
|
32
|
+
expect(getUnpkgHost).toHaveBeenCalledWith(registry);
|
|
27
33
|
});
|
|
28
34
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
test('runs mfe-purge-cache with host "https://unpkg.st.dev"', () => {
|
|
33
|
-
subject();
|
|
35
|
+
test('runs mfe-purge-cache', () => {
|
|
36
|
+
subject();
|
|
34
37
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
});
|
|
38
|
+
expect(runCommandOutput).toHaveBeenCalledWith(
|
|
39
|
+
`npx startup mfe-purge-cache --host ${unpkgHost} --package-name ${packageName} --tag ${tag}`
|
|
40
|
+
);
|
|
39
41
|
});
|
|
40
42
|
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DEV_MFE_REGISTRY, getMfeRegistry } from './get-mfe-registry';
|
|
2
|
+
|
|
3
|
+
const PROD_UNPKG_HOST = 'https://unpkg.servicetitan.com';
|
|
4
|
+
const DEV_UNPKG_HOST = 'https://unpkg.st.dev';
|
|
5
|
+
|
|
6
|
+
export function getUnpkgHost(registry?: string): string {
|
|
7
|
+
return getMfeRegistry(registry) === DEV_MFE_REGISTRY ? DEV_UNPKG_HOST : PROD_UNPKG_HOST;
|
|
8
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { npmWhoAmI } from '@servicetitan/install';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import readline from 'readline/promises';
|
|
4
|
+
import { isTTY, runCommand } from '../../utils';
|
|
5
|
+
import { DEV_MFE_REGISTRY, PROD_MFE_REGISTRY } from './get-mfe-registry';
|
|
6
|
+
|
|
7
|
+
const OKTA_REGISTRIES: string[] = [PROD_MFE_REGISTRY, DEV_MFE_REGISTRY];
|
|
8
|
+
|
|
9
|
+
export async function login(registry: string) {
|
|
10
|
+
if (npmWhoAmI({ registry }) !== undefined) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (!OKTA_REGISTRIES.includes(registry)) {
|
|
15
|
+
throw new Error(`Registry ${registry} is not recognized. Please log in manually.`);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const message = `This machine is not authorized to access ${registry}.`;
|
|
19
|
+
if (!isTTY()) {
|
|
20
|
+
throw new Error(message);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const answer = await ask(chalk.bold.cyan(`${message} Authorize? [Y/n] `));
|
|
24
|
+
if (answer && answer !== 'y') {
|
|
25
|
+
throw new Error('Not authorized');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
await runCommand(`npx --yes verdaccio-okta-oauth@latest --registry=${registry}`, {
|
|
29
|
+
quiet: true,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function ask(question: string) {
|
|
34
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
35
|
+
const answer = await rl.question(question);
|
|
36
|
+
rl.close();
|
|
37
|
+
return answer.trim().toLowerCase();
|
|
38
|
+
}
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import { runCommandOutput } from '../../utils';
|
|
2
|
-
|
|
3
|
-
const DEV_MFE_REGISTRY = 'https://verdaccio.st.dev';
|
|
4
|
-
const DEFAULT_UNPKG_HOST = 'https://unpkg.servicetitan.com';
|
|
5
|
-
const DEV_UNPKG_HOST = 'https://unpkg.st.dev';
|
|
2
|
+
import { getUnpkgHost } from './get-unpkg-host';
|
|
6
3
|
|
|
7
4
|
export function purgeCache(options: { packageName: string; registry?: string; tag: string }) {
|
|
8
5
|
const { packageName, registry, tag } = options;
|
|
9
|
-
const host = registry
|
|
6
|
+
const host = getUnpkgHost(registry);
|
|
10
7
|
runCommandOutput(
|
|
11
8
|
`npx startup mfe-purge-cache --host ${host} --package-name ${packageName} --tag ${tag}`
|
|
12
9
|
);
|
package/src/cli/index.ts
CHANGED
|
@@ -40,7 +40,8 @@ function addCommand(name: CommandName, y: typeof yargs) {
|
|
|
40
40
|
const { description, options: { _, ...options } = {} } = entry;
|
|
41
41
|
const nameWithArgs = name + (_?.description ? ` ${_.description}` : '');
|
|
42
42
|
const groupedOptions = Object.entries(options).reduce((result, [key, value]) => {
|
|
43
|
-
|
|
43
|
+
const suffix = /\W+$/.exec(key)?.[0] ?? ''; // fix for kebabCase dropping `\u00A0` suffixes
|
|
44
|
+
result[kebabCase(key) + suffix] = { group: 'Command Options:', ...value };
|
|
44
45
|
return result;
|
|
45
46
|
}, {} as CommandOptions);
|
|
46
47
|
const handler = (argv: any) => handleCommand(name, argv);
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import { createRequire } from 'module';
|
|
2
|
-
import fs from 'node:fs';
|
|
3
|
-
import os from 'node:os';
|
|
4
|
-
import path from 'node:path';
|
|
5
2
|
import { buildEscapedRegExp } from '../../build-escaped-reg-exp';
|
|
6
|
-
import { ViteBuildContext } from '../../types';
|
|
7
3
|
import { createResolveConfig } from '../create-resolve-config';
|
|
8
4
|
|
|
9
5
|
jest.mock('module', () => ({
|
|
@@ -13,7 +9,6 @@ jest.mock('module', () => ({
|
|
|
13
9
|
|
|
14
10
|
describe(`[startup] ${createResolveConfig.name}`, () => {
|
|
15
11
|
let startupRequire: { resolve: (specifier: string) => string };
|
|
16
|
-
let context: Partial<ViteBuildContext>;
|
|
17
12
|
let specifiers: string[];
|
|
18
13
|
|
|
19
14
|
beforeAll(() => {
|
|
@@ -25,23 +20,11 @@ describe(`[startup] ${createResolveConfig.name}`, () => {
|
|
|
25
20
|
jest.mocked(startupRequire.resolve).mockImplementation(() => {
|
|
26
21
|
throw new Error('Module not found');
|
|
27
22
|
});
|
|
28
|
-
const source = fs.mkdtempSync(path.join(os.tmpdir(), 'create-resolve-config-'));
|
|
29
|
-
context = { package: { source } as any };
|
|
30
23
|
specifiers = ['a', '@b/c'];
|
|
31
24
|
});
|
|
32
25
|
|
|
33
|
-
afterEach(() => fs.rmSync(context.package!.source, { recursive: true, force: true }));
|
|
34
|
-
|
|
35
|
-
function mockNodeModules(root: string, modules: string[]) {
|
|
36
|
-
modules.forEach(name => {
|
|
37
|
-
const dir = path.join(root, 'node_modules', ...name.split('/'));
|
|
38
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
39
|
-
fs.writeFileSync(path.join(dir, 'index.js'), '');
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
26
|
const subject = () =>
|
|
44
|
-
createResolveConfig(
|
|
27
|
+
createResolveConfig(specifiers) as {
|
|
45
28
|
alias: { find: RegExp; replacement: string }[];
|
|
46
29
|
};
|
|
47
30
|
|
|
@@ -49,14 +32,6 @@ describe(`[startup] ${createResolveConfig.name}`, () => {
|
|
|
49
32
|
expect(() => subject()).toThrow(/cannot resolve/i);
|
|
50
33
|
});
|
|
51
34
|
|
|
52
|
-
describe('when specifier is resolvable', () => {
|
|
53
|
-
beforeEach(() => mockNodeModules(context.package!.source, specifiers));
|
|
54
|
-
|
|
55
|
-
test('does nothing', () => {
|
|
56
|
-
expect(subject().alias).toEqual([]);
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
|
|
60
35
|
describe('when specifier is resolvable from startup', () => {
|
|
61
36
|
beforeEach(() => {
|
|
62
37
|
jest.mocked(startupRequire.resolve).mockImplementation(
|
|
@@ -65,20 +40,14 @@ describe(`[startup] ${createResolveConfig.name}`, () => {
|
|
|
65
40
|
});
|
|
66
41
|
|
|
67
42
|
test('emits alias', () => {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
expect(alias.find(({ find }) => find.test(specifier))?.replacement).toEqual(
|
|
72
|
-
`startup/${specifier}`
|
|
73
|
-
);
|
|
74
|
-
});
|
|
43
|
+
expect(subject().alias.map(({ replacement }) => replacement)).toEqual(
|
|
44
|
+
specifiers.map(specifier => `startup/${specifier}`)
|
|
45
|
+
);
|
|
75
46
|
});
|
|
76
47
|
|
|
77
48
|
test('alias matches whole specifier', () => {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
specifiers.forEach((specifier, i) =>
|
|
81
|
-
expect(alias[i].find).toEqual(buildEscapedRegExp(specifier))
|
|
49
|
+
expect(subject().alias.map(({ find }) => find)).toEqual(
|
|
50
|
+
specifiers.map(specifier => buildEscapedRegExp(specifier))
|
|
82
51
|
);
|
|
83
52
|
});
|
|
84
53
|
});
|
|
@@ -122,7 +122,7 @@ export function createBaseConfig(context: ViteBuildContext): InlineConfig {
|
|
|
122
122
|
),
|
|
123
123
|
...(getProcessEnv(context) ?? {}),
|
|
124
124
|
},
|
|
125
|
-
resolve: createResolveConfig(
|
|
125
|
+
resolve: createResolveConfig(optimizedStartupDependencies),
|
|
126
126
|
optimizeDeps: {
|
|
127
127
|
include: [
|
|
128
128
|
...optimizedStartupDependencies,
|
|
@@ -1,39 +1,25 @@
|
|
|
1
1
|
import { createRequire } from 'module';
|
|
2
|
-
import path from 'path';
|
|
3
2
|
import type { InlineConfig } from 'vite';
|
|
4
3
|
import { buildEscapedRegExp } from '../build-escaped-reg-exp';
|
|
5
|
-
import type { ViteBuildContext } from '../types';
|
|
6
4
|
|
|
7
5
|
type Result = InlineConfig['resolve'];
|
|
8
6
|
|
|
9
7
|
const startupRequire = createRequire(__filename);
|
|
10
8
|
|
|
11
9
|
/*
|
|
12
|
-
* Returns a resolver that
|
|
13
|
-
*
|
|
10
|
+
* Returns a resolver that resolves from startup's location. Use only for
|
|
11
|
+
* startup's internal dependencies that may not be directly resolvable by
|
|
12
|
+
* consumers using pnpm.
|
|
14
13
|
*/
|
|
15
|
-
export function createResolveConfig(
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
.map(specifier => ({
|
|
21
|
-
find: buildEscapedRegExp(specifier),
|
|
22
|
-
replacement: resolveFromStartup(specifier),
|
|
23
|
-
}));
|
|
14
|
+
export function createResolveConfig(specifiers: string[]): Result {
|
|
15
|
+
const alias = specifiers.map(specifier => ({
|
|
16
|
+
find: buildEscapedRegExp(specifier),
|
|
17
|
+
replacement: resolveFromStartup(specifier),
|
|
18
|
+
}));
|
|
24
19
|
|
|
25
20
|
return { alias };
|
|
26
21
|
}
|
|
27
22
|
|
|
28
|
-
function isResolvableFrom(specifier: string, source: string): boolean {
|
|
29
|
-
try {
|
|
30
|
-
require.resolve(specifier, { paths: [source] });
|
|
31
|
-
return true;
|
|
32
|
-
} catch {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
23
|
function resolveFromStartup(specifier: string): string {
|
|
38
24
|
try {
|
|
39
25
|
return startupRequire.resolve(specifier);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/utils/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB,uCAAuC,CAAC"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "DEFAULT_MFE_REGISTRY", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return DEFAULT_MFE_REGISTRY;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const DEFAULT_MFE_REGISTRY = 'https://verdaccio.servicetitan.com';
|
|
12
|
-
|
|
13
|
-
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/cli/commands/utils/constants.ts"],"sourcesContent":["export const DEFAULT_MFE_REGISTRY = 'https://verdaccio.servicetitan.com';\n"],"names":["DEFAULT_MFE_REGISTRY"],"mappings":";;;;+BAAaA;;;eAAAA;;;AAAN,MAAMA,uBAAuB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const DEFAULT_MFE_REGISTRY = 'https://verdaccio.servicetitan.com';
|