@servicetitan/startup 31.0.0 → 31.1.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/build.d.ts.map +1 -1
- package/dist/cli/commands/build.js +1 -7
- package/dist/cli/commands/build.js.map +1 -1
- package/dist/cli/commands/prepare-package.d.ts +1 -2
- package/dist/cli/commands/prepare-package.d.ts.map +1 -1
- package/dist/cli/commands/prepare-package.js +4 -6
- package/dist/cli/commands/prepare-package.js.map +1 -1
- package/dist/cli/commands/run-task.test.js +59 -0
- package/dist/cli/commands/run-task.test.js.map +1 -0
- package/dist/cli/commands/start.d.ts.map +1 -1
- package/dist/cli/commands/start.js +2 -11
- package/dist/cli/commands/start.js.map +1 -1
- package/dist/cli/tasks/swc-cli.d.js +3 -0
- package/dist/cli/tasks/swc-cli.d.js.map +1 -0
- package/dist/cli/tasks/swc-compile-package.d.ts.map +1 -1
- package/dist/cli/tasks/swc-compile-package.js +22 -19
- package/dist/cli/tasks/swc-compile-package.js.map +1 -1
- package/dist/cli/types/cpx2.d.js +3 -0
- package/dist/cli/types/cpx2.d.js.map +1 -0
- package/dist/cli/utils/bundle.d.ts +2 -2
- package/dist/cli/utils/bundle.d.ts.map +1 -1
- package/dist/cli/utils/bundle.js +18 -4
- package/dist/cli/utils/bundle.js.map +1 -1
- package/dist/cli/utils/copy-files.d.ts +1 -1
- package/dist/cli/utils/copy-files.d.ts.map +1 -1
- package/dist/cli/utils/copy-files.js +18 -11
- package/dist/cli/utils/copy-files.js.map +1 -1
- package/dist/cli/utils/get-module-type.d.ts.map +1 -1
- package/dist/cli/utils/get-module-type.js +2 -16
- package/dist/cli/utils/get-module-type.js.map +1 -1
- package/dist/cli/utils/index.d.ts +1 -1
- package/dist/cli/utils/index.d.ts.map +1 -1
- package/dist/cli/utils/index.js +1 -1
- package/dist/cli/utils/index.js.map +1 -1
- package/dist/cli/utils/ts-config.d.ts +11 -0
- package/dist/cli/utils/ts-config.d.ts.map +1 -0
- package/dist/cli/utils/ts-config.js +80 -0
- package/dist/cli/utils/ts-config.js.map +1 -0
- package/dist/utils/get-configuration.d.ts +1 -0
- package/dist/utils/get-configuration.d.ts.map +1 -1
- package/dist/utils/get-configuration.js +14 -0
- package/dist/utils/get-configuration.js.map +1 -1
- package/dist/webpack/configs/index.d.ts +0 -1
- package/dist/webpack/configs/index.d.ts.map +1 -1
- package/dist/webpack/configs/index.js +0 -1
- package/dist/webpack/configs/index.js.map +1 -1
- package/dist/webpack/configs/optimization-config.js +6 -6
- package/dist/webpack/configs/optimization-config.js.map +1 -1
- package/dist/webpack/configs/output-config.d.ts.map +1 -1
- package/dist/webpack/configs/output-config.js +3 -2
- package/dist/webpack/configs/output-config.js.map +1 -1
- package/dist/webpack/configs/plugins/html-plugin.d.ts +1 -1
- package/dist/webpack/configs/plugins/html-plugin.d.ts.map +1 -1
- package/dist/webpack/configs/plugins/html-plugin.js +2 -2
- package/dist/webpack/configs/plugins/html-plugin.js.map +1 -1
- package/dist/webpack/configs/plugins/virtual-modules-plugin.js +14 -4
- package/dist/webpack/configs/plugins/virtual-modules-plugin.js.map +1 -1
- package/dist/webpack/configs/utils/generate-metadata.d.ts.map +1 -1
- package/dist/webpack/configs/utils/generate-metadata.js +4 -0
- package/dist/webpack/configs/utils/generate-metadata.js.map +1 -1
- package/dist/webpack/create-webpack-config.d.ts.map +1 -1
- package/dist/webpack/create-webpack-config.js +0 -1
- package/dist/webpack/create-webpack-config.js.map +1 -1
- package/dist/webpack/types.d.ts +1 -0
- package/dist/webpack/types.d.ts.map +1 -1
- package/dist/webpack/utils/index.d.ts +0 -1
- package/dist/webpack/utils/index.d.ts.map +1 -1
- package/dist/webpack/utils/index.js +0 -1
- package/dist/webpack/utils/index.js.map +1 -1
- package/package.json +7 -8
- package/src/cli/commands/__tests__/build.test.ts +2 -4
- package/src/cli/commands/__tests__/prepare-package.test.ts +5 -28
- package/src/cli/commands/__tests__/start.test.ts +3 -5
- package/src/cli/commands/build.ts +0 -2
- package/src/cli/commands/prepare-package.ts +4 -7
- package/src/cli/commands/start.ts +1 -3
- package/src/cli/tasks/__tests__/swc-compile-package.test.ts +71 -12
- package/src/cli/tasks/swc-compile-package.ts +21 -20
- package/src/cli/utils/__tests__/bundle.test.ts +48 -7
- package/src/cli/utils/__tests__/copy-files.test.ts +5 -5
- package/src/cli/utils/bundle.ts +27 -5
- package/src/cli/utils/copy-files.ts +16 -6
- package/src/cli/utils/get-module-type.ts +2 -18
- package/src/cli/utils/index.ts +1 -1
- package/src/cli/utils/ts-config.ts +64 -0
- package/src/utils/__tests__/get-configuration.test.ts +20 -0
- package/src/utils/get-configuration.ts +12 -0
- package/src/webpack/__tests__/create-webpack-config-shared-dependencies.test.ts +0 -1
- package/src/webpack/__tests__/create-webpack-config-web-component.test.ts +17 -28
- package/src/webpack/__tests__/create-webpack-config.test.ts +27 -38
- package/src/webpack/configs/index.ts +0 -1
- package/src/webpack/configs/optimization-config.ts +6 -6
- package/src/webpack/configs/output-config.ts +4 -2
- package/src/webpack/configs/plugins/html-plugin.ts +5 -2
- package/src/webpack/configs/plugins/virtual-modules-plugin.ts +15 -2
- package/src/webpack/configs/utils/__tests__/generate-metadata.test.ts +3 -1
- package/src/webpack/configs/utils/generate-metadata.ts +6 -1
- package/src/webpack/create-webpack-config.ts +0 -2
- package/src/webpack/types.ts +1 -0
- package/src/webpack/utils/index.ts +0 -1
- package/dist/__mocks__/create-package.d.ts +0 -3
- package/dist/__mocks__/create-package.d.ts.map +0 -1
- package/dist/__mocks__/index.d.ts +0 -2
- package/dist/__mocks__/index.d.ts.map +0 -1
- package/dist/cli/commands/review/__mocks__/expect-calls.d.ts +0 -23
- package/dist/cli/commands/review/__mocks__/expect-calls.d.ts.map +0 -1
- package/dist/cli/commands/review/__mocks__/index.d.ts +0 -2
- package/dist/cli/commands/review/__mocks__/index.d.ts.map +0 -1
- package/dist/cli/commands/review/rules/__mocks__/index.d.ts +0 -4
- package/dist/cli/commands/review/rules/__mocks__/index.d.ts.map +0 -1
- package/dist/cli/commands/review/rules/__mocks__/mock-config.d.ts +0 -7
- package/dist/cli/commands/review/rules/__mocks__/mock-config.d.ts.map +0 -1
- package/dist/cli/commands/review/rules/__mocks__/mock-packages.d.ts +0 -21
- package/dist/cli/commands/review/rules/__mocks__/mock-packages.d.ts.map +0 -1
- package/dist/cli/commands/review/rules/__mocks__/mock-project.d.ts +0 -3
- package/dist/cli/commands/review/rules/__mocks__/mock-project.d.ts.map +0 -1
- package/dist/cli/utils/style-extensions.d.ts +0 -2
- package/dist/cli/utils/style-extensions.d.ts.map +0 -1
- package/dist/cli/utils/style-extensions.js +0 -17
- package/dist/cli/utils/style-extensions.js.map +0 -1
- package/dist/cli/utils/tcm.d.ts +0 -6
- package/dist/cli/utils/tcm.d.ts.map +0 -1
- package/dist/cli/utils/tcm.js +0 -72
- package/dist/cli/utils/tcm.js.map +0 -1
- package/dist/webpack/__mocks__/file-rules.d.ts +0 -3
- package/dist/webpack/__mocks__/file-rules.d.ts.map +0 -1
- package/dist/webpack/__mocks__/index.d.ts +0 -3
- package/dist/webpack/__mocks__/index.d.ts.map +0 -1
- package/dist/webpack/__mocks__/style-rules.d.ts +0 -8
- package/dist/webpack/__mocks__/style-rules.d.ts.map +0 -1
- package/dist/webpack/configs/cache-config.d.ts +0 -6
- package/dist/webpack/configs/cache-config.d.ts.map +0 -1
- package/dist/webpack/configs/cache-config.js +0 -34
- package/dist/webpack/configs/cache-config.js.map +0 -1
- package/dist/webpack/utils/feature-cohort.d.ts +0 -5
- package/dist/webpack/utils/feature-cohort.d.ts.map +0 -1
- package/dist/webpack/utils/feature-cohort.js +0 -26
- package/dist/webpack/utils/feature-cohort.js.map +0 -1
- package/dist/webpack/utils/hash-mod.d.ts +0 -9
- package/dist/webpack/utils/hash-mod.d.ts.map +0 -1
- package/dist/webpack/utils/hash-mod.js +0 -39
- package/dist/webpack/utils/hash-mod.js.map +0 -1
- package/src/cli/utils/__tests__/tcm.test.ts +0 -195
- package/src/cli/utils/style-extensions.ts +0 -1
- package/src/cli/utils/tcm.ts +0 -66
- package/src/webpack/configs/cache-config.ts +0 -25
- package/src/webpack/utils/feature-cohort.ts +0 -19
- package/src/webpack/utils/hash-mod.ts +0 -32
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @jest-environment node
|
|
3
|
-
*/
|
|
4
|
-
import chokidar from 'chokidar';
|
|
5
|
-
import fs, { Stats } from 'fs';
|
|
6
|
-
|
|
7
|
-
import { getFolders, log } from '../../../utils';
|
|
8
|
-
import * as sassModule from '../compile-sass';
|
|
9
|
-
|
|
10
|
-
import { styleExtensions } from '../style-extensions';
|
|
11
|
-
import { tcm } from '../tcm';
|
|
12
|
-
|
|
13
|
-
jest.mock('../../../utils', () => ({
|
|
14
|
-
...jest.requireActual('../../../utils'),
|
|
15
|
-
getFolders: jest.fn(),
|
|
16
|
-
log: { debug: jest.fn(), error: jest.fn(), info: jest.fn() }, // suppress test output
|
|
17
|
-
}));
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Note: These tests don't use memfs because the typed-css-modules package
|
|
21
|
-
* uses node: URLs to import the fs modules, which bypasses the memfs filesystem
|
|
22
|
-
* (as of memfs ~4.6.0).
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
describe('[startup] Cli Utils', () => {
|
|
26
|
-
const source = fs.mkdtempSync('src');
|
|
27
|
-
|
|
28
|
-
beforeEach(() => {
|
|
29
|
-
jest.resetAllMocks();
|
|
30
|
-
jest.mocked(getFolders).mockReturnValue({ source, destination: 'dist' });
|
|
31
|
-
fs.readdirSync(source).forEach(file => fs.rmSync(`${source}/${file}`));
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
afterAll(() => fs.rmSync(source, { recursive: true }));
|
|
35
|
-
|
|
36
|
-
function mockStylesModule(module: string, id = 'foo') {
|
|
37
|
-
const content = `.${id} { display: none; }`;
|
|
38
|
-
fs.writeFileSync(`${source}/${module}`, content);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function expectTypeDefinitions(module: string, id = 'foo') {
|
|
42
|
-
expect(fs.readFileSync(`${source}/${module}.d.ts`, 'utf8')).toContain(
|
|
43
|
-
`export const ${id}: string;`
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
describe(`${tcm.name}`, () => {
|
|
48
|
-
const subject = async () => tcm(options);
|
|
49
|
-
let options: Parameters<typeof tcm>[0];
|
|
50
|
-
|
|
51
|
-
beforeEach(() => {
|
|
52
|
-
options = undefined;
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
describe.each(styleExtensions)('with %s module', extension => {
|
|
56
|
-
const module = `foo.module.${extension}`;
|
|
57
|
-
|
|
58
|
-
beforeEach(() => mockStylesModule(module));
|
|
59
|
-
|
|
60
|
-
test(`generates Typescript definitions for ${extension} module`, async () => {
|
|
61
|
-
await subject();
|
|
62
|
-
|
|
63
|
-
expectTypeDefinitions(module);
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
describe('when an error occurs', () => {
|
|
68
|
-
beforeEach(() => {
|
|
69
|
-
mockStylesModule('foo.module.scss');
|
|
70
|
-
jest.spyOn(sassModule, 'compileSass').mockImplementation(() => {
|
|
71
|
-
throw new Error('Oops!');
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
test('logs error', async () => {
|
|
76
|
-
await subject();
|
|
77
|
-
|
|
78
|
-
expect(log.error).toHaveBeenCalledWith(expect.stringContaining('Oops!'));
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
describe(`watch mode`, () => {
|
|
83
|
-
type Listener = (path: string) => Promise<void>;
|
|
84
|
-
let watchSpy: jest.SpyInstance;
|
|
85
|
-
let fsWatcher: Partial<ReturnType<typeof chokidar.watch>>;
|
|
86
|
-
|
|
87
|
-
beforeEach(() => {
|
|
88
|
-
options = { watch: true };
|
|
89
|
-
fsWatcher = { on: jest.fn() };
|
|
90
|
-
watchSpy = jest.spyOn(chokidar, 'watch').mockReturnValue(fsWatcher as any);
|
|
91
|
-
fs.writeFileSync(`${source}/foo.bar`, '');
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
test('watches for new and changed style modules', async () => {
|
|
95
|
-
await subject();
|
|
96
|
-
|
|
97
|
-
expect(watchSpy).toHaveBeenCalledWith(source, {
|
|
98
|
-
ignored: expect.any(Function),
|
|
99
|
-
ignoreInitial: true,
|
|
100
|
-
});
|
|
101
|
-
expect(fsWatcher.on).toHaveBeenCalledWith('add', expect.any(Function));
|
|
102
|
-
expect(fsWatcher.on).toHaveBeenCalledWith('change', expect.any(Function));
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
function getListener(name: string) {
|
|
106
|
-
const { calls } = jest.mocked(fsWatcher.on)!.mock;
|
|
107
|
-
return calls.find(([event]) => event === name)![1] as Listener;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
describe('"ignored" filter', () => {
|
|
111
|
-
const styleExtensions = ['.module.css', '.module.scss', '.module.less'];
|
|
112
|
-
let ignored: (path: string, stats?: Partial<Stats>) => boolean;
|
|
113
|
-
let filePath: string;
|
|
114
|
-
let stats: Partial<Stats> | undefined;
|
|
115
|
-
|
|
116
|
-
beforeEach(async () => {
|
|
117
|
-
await tcm(options);
|
|
118
|
-
const { calls } = watchSpy.mock;
|
|
119
|
-
ignored = calls[0][1].ignored;
|
|
120
|
-
stats = { isFile: () => true };
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
const subject = () => ignored(filePath, stats);
|
|
124
|
-
|
|
125
|
-
function itReturns(value: boolean) {
|
|
126
|
-
test(`returns ${value}`, () => expect(subject()).toBe(value));
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
describe.each(styleExtensions)('when path ends with %s', ext => {
|
|
130
|
-
beforeEach(() => (filePath = `foo${ext}`));
|
|
131
|
-
|
|
132
|
-
itReturns(false);
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
describe.each(styleExtensions)('when path contains %s', ext => {
|
|
136
|
-
beforeEach(() => (filePath = `foo${ext}.d.ts`));
|
|
137
|
-
|
|
138
|
-
itReturns(true);
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
describe.each(['', '.scss', '.tsx'])('when path ends with "%s"', ext => {
|
|
142
|
-
beforeEach(() => (filePath = `foo${ext}`));
|
|
143
|
-
|
|
144
|
-
itReturns(true);
|
|
145
|
-
|
|
146
|
-
describe('when stats is undefined', () => {
|
|
147
|
-
beforeEach(() => (stats = undefined));
|
|
148
|
-
|
|
149
|
-
itReturns(false);
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
describe('when stats.isFile returns false', () => {
|
|
153
|
-
beforeEach(() => (stats = { isFile: () => false }));
|
|
154
|
-
|
|
155
|
-
itReturns(false);
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
describe('when module is added', () => {
|
|
161
|
-
const module = 'bar.module.scss';
|
|
162
|
-
|
|
163
|
-
const setup = async () => {
|
|
164
|
-
await subject();
|
|
165
|
-
mockStylesModule(module, 'bar');
|
|
166
|
-
await getListener('add')(`${source}/${module}`);
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
test('generates Typescript definitions for new module', async () => {
|
|
170
|
-
await setup();
|
|
171
|
-
|
|
172
|
-
expectTypeDefinitions(module, 'bar');
|
|
173
|
-
});
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
describe('when module is changed', () => {
|
|
177
|
-
const module = 'baz.module.less';
|
|
178
|
-
|
|
179
|
-
const setup = async () => {
|
|
180
|
-
mockStylesModule(module, 'foo');
|
|
181
|
-
await subject();
|
|
182
|
-
|
|
183
|
-
mockStylesModule(module, 'baz');
|
|
184
|
-
await getListener('change')(`${source}/${module}`);
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
test('generates Typescript definitions for changed module', async () => {
|
|
188
|
-
await setup();
|
|
189
|
-
|
|
190
|
-
expectTypeDefinitions(module, 'baz');
|
|
191
|
-
});
|
|
192
|
-
});
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const styleExtensions = ['css', 'less', 'scss'];
|
package/src/cli/utils/tcm.ts
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { glob } from 'glob';
|
|
2
|
-
import chokidar from 'chokidar';
|
|
3
|
-
import DtsCreator from 'typed-css-modules';
|
|
4
|
-
|
|
5
|
-
import { getFolders, log } from '../../utils';
|
|
6
|
-
import { compileLess } from './compile-less';
|
|
7
|
-
import { compileSass } from './compile-sass';
|
|
8
|
-
import { styleExtensions } from './style-extensions';
|
|
9
|
-
|
|
10
|
-
interface RunOptions {
|
|
11
|
-
watch?: boolean;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
async function compile(filePath: string) {
|
|
15
|
-
if (filePath.endsWith('.less')) {
|
|
16
|
-
return compileLess(filePath);
|
|
17
|
-
}
|
|
18
|
-
if (filePath.endsWith('.scss')) {
|
|
19
|
-
return compileSass(filePath);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export async function tcm({ watch }: RunOptions = {}) {
|
|
24
|
-
const source = getFolders().source.replace(/\\/g, '/');
|
|
25
|
-
const filesPattern = `${source}/**/*.module.{${styleExtensions.join()}}`;
|
|
26
|
-
const creator = new DtsCreator({ camelCase: true, namedExports: true });
|
|
27
|
-
|
|
28
|
-
const generateDefinitions = async (file: string) => {
|
|
29
|
-
try {
|
|
30
|
-
const css = await compile(file);
|
|
31
|
-
const content = await creator.create(file, css, !!watch);
|
|
32
|
-
await content.writeFile();
|
|
33
|
-
} catch (error) {
|
|
34
|
-
log.error(String(error));
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
if (!watch) {
|
|
39
|
-
log.info(`Generating types for ${filesPattern}`);
|
|
40
|
-
const files = await glob(filesPattern);
|
|
41
|
-
await Promise.all(files.map(generateDefinitions));
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
log.info(`Watching to generate types for ${filesPattern}`);
|
|
46
|
-
|
|
47
|
-
watchFiles(source, async (path: string) => {
|
|
48
|
-
log.debug('tcm', `Compiling ${path}`);
|
|
49
|
-
await generateDefinitions(path);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
/* istanbul ignore next: not executed in test environment */
|
|
53
|
-
if (process.env.NODE_ENV !== 'test') {
|
|
54
|
-
await new Promise<void>(() => {});
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function watchFiles(source: string, callback: (path: string) => Promise<void>) {
|
|
59
|
-
const stylesRegex = new RegExp(`\\.module\\.(${styleExtensions.join('|')})$`);
|
|
60
|
-
const watcher = chokidar.watch(source, {
|
|
61
|
-
ignored: (path, stats) => !!stats?.isFile() && !stylesRegex.test(path),
|
|
62
|
-
ignoreInitial: true,
|
|
63
|
-
});
|
|
64
|
-
watcher.on('add', callback);
|
|
65
|
-
watcher.on('change', callback);
|
|
66
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { Configuration } from 'webpack';
|
|
2
|
-
import { getPackageName, log } from '../../utils';
|
|
3
|
-
import { featureCohort } from '../utils';
|
|
4
|
-
import { Context, Overrides } from './types';
|
|
5
|
-
|
|
6
|
-
type Result = Pick<Configuration, 'cache'> | undefined;
|
|
7
|
-
|
|
8
|
-
export function cacheConfig(context: Context, _: Overrides): Result {
|
|
9
|
-
const { embed, isProduction, isWebComponent } = context;
|
|
10
|
-
if (isProduction) {
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
return featureCohort([2, 5], () => {
|
|
15
|
-
const packageName = getPackageName();
|
|
16
|
-
log.info('Persistent cache is active');
|
|
17
|
-
return {
|
|
18
|
-
cache: {
|
|
19
|
-
type: 'filesystem',
|
|
20
|
-
name: isWebComponent ? `${packageName}__${embed ? 'light' : 'full'}` : packageName,
|
|
21
|
-
profile: true,
|
|
22
|
-
},
|
|
23
|
-
};
|
|
24
|
-
});
|
|
25
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { sync as username } from 'username';
|
|
2
|
-
|
|
3
|
-
import { log } from '../../utils';
|
|
4
|
-
|
|
5
|
-
import { hashMod } from './hash-mod';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Allows to enable feature for part of the auditory based on stable trait (username).
|
|
9
|
-
*/
|
|
10
|
-
export function featureCohort<T>([limit, total]: [number, number], fn: () => T): T | undefined {
|
|
11
|
-
if (limit >= total) {
|
|
12
|
-
log.warning('featureCohort: feature always active');
|
|
13
|
-
}
|
|
14
|
-
const mod = hashMod(total);
|
|
15
|
-
const cohort = mod(username() ?? '');
|
|
16
|
-
if (cohort < limit) {
|
|
17
|
-
return fn();
|
|
18
|
-
}
|
|
19
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* salvaged from https://github.com/segment-boneyard/hash-mod
|
|
3
|
-
* 1. recent code from repo never got into npm registry
|
|
4
|
-
* 2. no types in DefinitelyTyped
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Returns a `hashMod` function that will return an integer hash of a string
|
|
9
|
-
* modded by `buckets`.
|
|
10
|
-
*
|
|
11
|
-
* @param {Number} buckets
|
|
12
|
-
* @return {Function}
|
|
13
|
-
*/
|
|
14
|
-
export function hashMod(buckets: number) {
|
|
15
|
-
return function (string: string) {
|
|
16
|
-
return integerHash(string) % buckets;
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Return the integer hash of a `string`.
|
|
22
|
-
*
|
|
23
|
-
* http://stackoverflow.com/questions/2624192/good-hash-function-for-strings
|
|
24
|
-
*
|
|
25
|
-
* @param {String} string
|
|
26
|
-
* @returns {Number}
|
|
27
|
-
*/
|
|
28
|
-
function integerHash(string: string) {
|
|
29
|
-
return (string + '').split('').reduce(function (memo, item) {
|
|
30
|
-
return (memo * 31 * item.charCodeAt(0)) % 982451653;
|
|
31
|
-
}, 7);
|
|
32
|
-
}
|