@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
|
@@ -3,10 +3,13 @@ import HtmlWebpackPlugin, { Options as HtmlWebpackPluginOptions } from 'html-web
|
|
|
3
3
|
import { splitByEntry } from '../../utils';
|
|
4
4
|
import { Context, Overrides } from '../types';
|
|
5
5
|
|
|
6
|
-
export function htmlPlugin(
|
|
6
|
+
export function htmlPlugin(
|
|
7
|
+
{ embed, headless, isWebComponent, name }: Context,
|
|
8
|
+
{ plugins }: Overrides
|
|
9
|
+
) {
|
|
7
10
|
const { HtmlWebpackPlugin: htmlWebpackPluginOptions = {} } = plugins ?? {};
|
|
8
11
|
|
|
9
|
-
if (embed) {
|
|
12
|
+
if (embed || headless) {
|
|
10
13
|
return;
|
|
11
14
|
}
|
|
12
15
|
|
|
@@ -34,7 +34,11 @@ function designSystemCode() {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
function indexCode(context: Context) {
|
|
37
|
-
const { embed = false, isLegacyRoot, sharedDependencies } = context;
|
|
37
|
+
const { embed = false, headless, isLegacyRoot, sharedDependencies } = context;
|
|
38
|
+
if (headless) {
|
|
39
|
+
return headlessIndex();
|
|
40
|
+
}
|
|
41
|
+
|
|
38
42
|
const options = `{ legacyRoot: ${isLegacyRoot}, sharedDependenciesNames: ${JSON.stringify(
|
|
39
43
|
Object.keys(sharedDependencies)
|
|
40
44
|
)} }`;
|
|
@@ -46,11 +50,20 @@ function indexCode(context: Context) {
|
|
|
46
50
|
].join('\n');
|
|
47
51
|
}
|
|
48
52
|
|
|
49
|
-
function needsToIncludeDesignSystem({ embed, packageData, sharedDependencies }: Context) {
|
|
53
|
+
function needsToIncludeDesignSystem({ embed, headless, packageData, sharedDependencies }: Context) {
|
|
50
54
|
return (
|
|
55
|
+
!headless &&
|
|
51
56
|
// Depends on design system
|
|
52
57
|
!!packageData.dependencies['@servicetitan/design-system'] &&
|
|
53
58
|
// ... and is not light bundle with private copy of design system
|
|
54
59
|
!(embed && !!sharedDependencies['@servicetitan/design-system'])
|
|
55
60
|
);
|
|
56
61
|
}
|
|
62
|
+
|
|
63
|
+
function headlessIndex() {
|
|
64
|
+
return [
|
|
65
|
+
"import { registerHeadless } from '@servicetitan/web-components';",
|
|
66
|
+
"import { connectedCallback, disconnectedCallback } from './headless';",
|
|
67
|
+
'registerHeadless(connectedCallback, disconnectedCallback);',
|
|
68
|
+
].join('\n');
|
|
69
|
+
}
|
|
@@ -67,12 +67,14 @@ describe(`[startup] ${generateMetadata.name}`, () => {
|
|
|
67
67
|
describe('when package has entrypoints', () => {
|
|
68
68
|
const full = { css: 'foo', js: 'bar ' };
|
|
69
69
|
const light = { css: 'baz', js: 'qux' };
|
|
70
|
+
const headless = { css: 'quux', js: 'waldo' };
|
|
70
71
|
|
|
71
72
|
beforeEach(() => {
|
|
72
73
|
vol.fromJSON({
|
|
73
74
|
...packageFS(),
|
|
74
75
|
[`${destination}/bundle/full/entrypoints.json`]: JSON.stringify(full),
|
|
75
76
|
[`${destination}/bundle/light/entrypoints.json`]: JSON.stringify(light),
|
|
77
|
+
[`${destination}/bundle/headless/entrypoints.json`]: JSON.stringify(headless),
|
|
76
78
|
});
|
|
77
79
|
});
|
|
78
80
|
|
|
@@ -80,7 +82,7 @@ describe(`[startup] ${generateMetadata.name}`, () => {
|
|
|
80
82
|
subject();
|
|
81
83
|
|
|
82
84
|
expect(generatedMetadata(destination)).toEqual(
|
|
83
|
-
expect.objectContaining({ entrypoints: { full, light } })
|
|
85
|
+
expect.objectContaining({ entrypoints: { full, light, headless } })
|
|
84
86
|
);
|
|
85
87
|
});
|
|
86
88
|
});
|
|
@@ -15,6 +15,7 @@ export function generateMetadata(context: Context) {
|
|
|
15
15
|
|
|
16
16
|
const full = readJsonSafe(path.join(destination, 'bundle', 'full', 'entrypoints.json'));
|
|
17
17
|
const light = readJsonSafe(path.join(destination, 'bundle', 'light', 'entrypoints.json'));
|
|
18
|
+
const headless = readJsonSafe(path.join(destination, 'bundle', 'headless', 'entrypoints.json'));
|
|
18
19
|
const metadata: Metadata = {
|
|
19
20
|
name,
|
|
20
21
|
version: packageData.version,
|
|
@@ -25,7 +26,11 @@ export function generateMetadata(context: Context) {
|
|
|
25
26
|
},
|
|
26
27
|
sharedDependencies,
|
|
27
28
|
dependencies: packageData.dependencies,
|
|
28
|
-
entrypoints: {
|
|
29
|
+
entrypoints: {
|
|
30
|
+
...(full ? { full } : {}),
|
|
31
|
+
...(light ? { light } : {}),
|
|
32
|
+
...(headless ? { headless } : {}),
|
|
33
|
+
},
|
|
29
34
|
};
|
|
30
35
|
|
|
31
36
|
const outputFile = path.join(destination, 'metadata.json');
|
|
@@ -17,7 +17,6 @@ import {
|
|
|
17
17
|
import {
|
|
18
18
|
Context,
|
|
19
19
|
amdConfig,
|
|
20
|
-
cacheConfig,
|
|
21
20
|
devServerConfig,
|
|
22
21
|
devtoolConfig,
|
|
23
22
|
entryConfig,
|
|
@@ -67,7 +66,6 @@ export function createWebpackConfig(overrides: Overrides, options: Options = {})
|
|
|
67
66
|
const result = merge(
|
|
68
67
|
[
|
|
69
68
|
amdConfig,
|
|
70
|
-
cacheConfig,
|
|
71
69
|
devServerConfig,
|
|
72
70
|
devtoolConfig,
|
|
73
71
|
entryConfig,
|
package/src/webpack/types.ts
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"create-package.d.ts","sourceRoot":"","sources":["../../src/__mocks__/create-package.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAe,MAAM,UAAU,CAAC;AAEhD,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAU9D"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/__mocks__/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Asserts that a sequence of mock function calls occurred in the specified order,
|
|
3
|
-
* with the specified arguments for each call.
|
|
4
|
-
*
|
|
5
|
-
* Each argument to this function should be either:
|
|
6
|
-
* - a mock function (jest.Mock), or
|
|
7
|
-
* - an array where the first element is a mock function and the rest are the expected arguments for that call.
|
|
8
|
-
*
|
|
9
|
-
* For each call, this function checks:
|
|
10
|
-
* - The mock was called with the expected arguments (if provided).
|
|
11
|
-
* - The call order is strictly increasing (i.e., each call happened after the previous one).
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* expectCalls(
|
|
15
|
-
* [mockA, 1, 2],
|
|
16
|
-
* [mockB, 'foo'],
|
|
17
|
-
* mockC
|
|
18
|
-
* );
|
|
19
|
-
*
|
|
20
|
-
* @param {...any[]} calls - Sequence of [mockFn, ...args] or mockFn to check call order and arguments.
|
|
21
|
-
*/
|
|
22
|
-
export declare function expectCalls(...calls: any[]): void;
|
|
23
|
-
//# sourceMappingURL=expect-calls.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"expect-calls.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/review/__mocks__/expect-calls.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,wBAAgB,WAAW,CAAC,GAAG,KAAK,EAAE,GAAG,EAAE,QAqB1C"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/review/__mocks__/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/review/rules/__mocks__/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mock-config.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/review/rules/__mocks__/mock-config.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAElD,wBAAgB,UAAU,CAAC,EACvB,EAAE,EACF,KAAe,EACf,OAAY,GACf,EAAE;IACC,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IACzB,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CAC9B,GAAG,mBAAmB,CAEtB"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Dependencies, Package } from '../../types';
|
|
2
|
-
/**
|
|
3
|
-
* Generates an array of mock Package objects based on a dependencies map.
|
|
4
|
-
*
|
|
5
|
-
* Each dependency entry can specify multiple versions, and each version can be used by multiple package names.
|
|
6
|
-
* The resulting packages will have their dependencies set accordingly.
|
|
7
|
-
*
|
|
8
|
-
* @param {Dependencies} dependencies - An object mapping dependency names to version maps,
|
|
9
|
-
* where each version maps to an array of package names that depend on that version.
|
|
10
|
-
*
|
|
11
|
-
* @returns {Package[]} An array of Package objects with the specified dependencies.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* const deps = {
|
|
15
|
-
* lodash: { '4.17.21': ['foo', 'bar'], '4.17.20': ['baz'] }
|
|
16
|
-
* };
|
|
17
|
-
* const pkgs = mockPackages(deps);
|
|
18
|
-
* // pkgs will include packages 'foo', 'bar', and 'baz' with appropriate lodash dependencies.
|
|
19
|
-
*/
|
|
20
|
-
export declare function mockPackages(dependencies: Dependencies): Package[];
|
|
21
|
-
//# sourceMappingURL=mock-packages.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mock-packages.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/review/rules/__mocks__/mock-packages.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEpD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,YAAY,CAAC,YAAY,EAAE,YAAY,GAAG,OAAO,EAAE,CAmBlE"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mock-project.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/review/rules/__mocks__/mock-project.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEtC,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAQ9D"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"style-extensions.d.ts","sourceRoot":"","sources":["../../../src/cli/utils/style-extensions.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe,UAA0B,CAAC"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "styleExtensions", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return styleExtensions;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const styleExtensions = [
|
|
12
|
-
'css',
|
|
13
|
-
'less',
|
|
14
|
-
'scss'
|
|
15
|
-
];
|
|
16
|
-
|
|
17
|
-
//# sourceMappingURL=style-extensions.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/cli/utils/style-extensions.ts"],"sourcesContent":["export const styleExtensions = ['css', 'less', 'scss'];\n"],"names":["styleExtensions"],"mappings":";;;;+BAAaA;;;eAAAA;;;AAAN,MAAMA,kBAAkB;IAAC;IAAO;IAAQ;CAAO"}
|
package/dist/cli/utils/tcm.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tcm.d.ts","sourceRoot":"","sources":["../../../src/cli/utils/tcm.ts"],"names":[],"mappings":"AASA,UAAU,UAAU;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;CACnB;AAWD,wBAAsB,GAAG,CAAC,EAAE,KAAK,EAAE,GAAE,UAAe,iBAiCnD"}
|
package/dist/cli/utils/tcm.js
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "tcm", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return tcm;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _glob = require("glob");
|
|
12
|
-
const _chokidar = /*#__PURE__*/ _interop_require_default(require("chokidar"));
|
|
13
|
-
const _typedcssmodules = /*#__PURE__*/ _interop_require_default(require("typed-css-modules"));
|
|
14
|
-
const _utils = require("../../utils");
|
|
15
|
-
const _compileless = require("./compile-less");
|
|
16
|
-
const _compilesass = require("./compile-sass");
|
|
17
|
-
const _styleextensions = require("./style-extensions");
|
|
18
|
-
function _interop_require_default(obj) {
|
|
19
|
-
return obj && obj.__esModule ? obj : {
|
|
20
|
-
default: obj
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
async function compile(filePath) {
|
|
24
|
-
if (filePath.endsWith('.less')) {
|
|
25
|
-
return (0, _compileless.compileLess)(filePath);
|
|
26
|
-
}
|
|
27
|
-
if (filePath.endsWith('.scss')) {
|
|
28
|
-
return (0, _compilesass.compileSass)(filePath);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
async function tcm({ watch } = {}) {
|
|
32
|
-
const source = (0, _utils.getFolders)().source.replace(/\\/g, '/');
|
|
33
|
-
const filesPattern = `${source}/**/*.module.{${_styleextensions.styleExtensions.join()}}`;
|
|
34
|
-
const creator = new _typedcssmodules.default({
|
|
35
|
-
camelCase: true,
|
|
36
|
-
namedExports: true
|
|
37
|
-
});
|
|
38
|
-
const generateDefinitions = async (file)=>{
|
|
39
|
-
try {
|
|
40
|
-
const css = await compile(file);
|
|
41
|
-
const content = await creator.create(file, css, !!watch);
|
|
42
|
-
await content.writeFile();
|
|
43
|
-
} catch (error) {
|
|
44
|
-
_utils.log.error(String(error));
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
if (!watch) {
|
|
48
|
-
_utils.log.info(`Generating types for ${filesPattern}`);
|
|
49
|
-
const files = await (0, _glob.glob)(filesPattern);
|
|
50
|
-
await Promise.all(files.map(generateDefinitions));
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
_utils.log.info(`Watching to generate types for ${filesPattern}`);
|
|
54
|
-
watchFiles(source, async (path)=>{
|
|
55
|
-
_utils.log.debug('tcm', `Compiling ${path}`);
|
|
56
|
-
await generateDefinitions(path);
|
|
57
|
-
});
|
|
58
|
-
/* istanbul ignore next: not executed in test environment */ if (process.env.NODE_ENV !== 'test') {
|
|
59
|
-
await new Promise(()=>{});
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
function watchFiles(source, callback) {
|
|
63
|
-
const stylesRegex = new RegExp(`\\.module\\.(${_styleextensions.styleExtensions.join('|')})$`);
|
|
64
|
-
const watcher = _chokidar.default.watch(source, {
|
|
65
|
-
ignored: (path, stats)=>!!(stats === null || stats === void 0 ? void 0 : stats.isFile()) && !stylesRegex.test(path),
|
|
66
|
-
ignoreInitial: true
|
|
67
|
-
});
|
|
68
|
-
watcher.on('add', callback);
|
|
69
|
-
watcher.on('change', callback);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
//# sourceMappingURL=tcm.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/cli/utils/tcm.ts"],"sourcesContent":["import { glob } from 'glob';\nimport chokidar from 'chokidar';\nimport DtsCreator from 'typed-css-modules';\n\nimport { getFolders, log } from '../../utils';\nimport { compileLess } from './compile-less';\nimport { compileSass } from './compile-sass';\nimport { styleExtensions } from './style-extensions';\n\ninterface RunOptions {\n watch?: boolean;\n}\n\nasync function compile(filePath: string) {\n if (filePath.endsWith('.less')) {\n return compileLess(filePath);\n }\n if (filePath.endsWith('.scss')) {\n return compileSass(filePath);\n }\n}\n\nexport async function tcm({ watch }: RunOptions = {}) {\n const source = getFolders().source.replace(/\\\\/g, '/');\n const filesPattern = `${source}/**/*.module.{${styleExtensions.join()}}`;\n const creator = new DtsCreator({ camelCase: true, namedExports: true });\n\n const generateDefinitions = async (file: string) => {\n try {\n const css = await compile(file);\n const content = await creator.create(file, css, !!watch);\n await content.writeFile();\n } catch (error) {\n log.error(String(error));\n }\n };\n\n if (!watch) {\n log.info(`Generating types for ${filesPattern}`);\n const files = await glob(filesPattern);\n await Promise.all(files.map(generateDefinitions));\n return;\n }\n\n log.info(`Watching to generate types for ${filesPattern}`);\n\n watchFiles(source, async (path: string) => {\n log.debug('tcm', `Compiling ${path}`);\n await generateDefinitions(path);\n });\n\n /* istanbul ignore next: not executed in test environment */\n if (process.env.NODE_ENV !== 'test') {\n await new Promise<void>(() => {});\n }\n}\n\nfunction watchFiles(source: string, callback: (path: string) => Promise<void>) {\n const stylesRegex = new RegExp(`\\\\.module\\\\.(${styleExtensions.join('|')})$`);\n const watcher = chokidar.watch(source, {\n ignored: (path, stats) => !!stats?.isFile() && !stylesRegex.test(path),\n ignoreInitial: true,\n });\n watcher.on('add', callback);\n watcher.on('change', callback);\n}\n"],"names":["tcm","compile","filePath","endsWith","compileLess","compileSass","watch","source","getFolders","replace","filesPattern","styleExtensions","join","creator","DtsCreator","camelCase","namedExports","generateDefinitions","file","css","content","create","writeFile","error","log","String","info","files","glob","Promise","all","map","watchFiles","path","debug","process","env","NODE_ENV","callback","stylesRegex","RegExp","watcher","chokidar","ignored","stats","isFile","test","ignoreInitial","on"],"mappings":";;;;+BAsBsBA;;;eAAAA;;;sBAtBD;iEACA;wEACE;uBAES;6BACJ;6BACA;iCACI;;;;;;AAMhC,eAAeC,QAAQC,QAAgB;IACnC,IAAIA,SAASC,QAAQ,CAAC,UAAU;QAC5B,OAAOC,IAAAA,wBAAW,EAACF;IACvB;IACA,IAAIA,SAASC,QAAQ,CAAC,UAAU;QAC5B,OAAOE,IAAAA,wBAAW,EAACH;IACvB;AACJ;AAEO,eAAeF,IAAI,EAAEM,KAAK,EAAc,GAAG,CAAC,CAAC;IAChD,MAAMC,SAASC,IAAAA,iBAAU,IAAGD,MAAM,CAACE,OAAO,CAAC,OAAO;IAClD,MAAMC,eAAe,GAAGH,OAAO,cAAc,EAAEI,gCAAe,CAACC,IAAI,GAAG,CAAC,CAAC;IACxE,MAAMC,UAAU,IAAIC,wBAAU,CAAC;QAAEC,WAAW;QAAMC,cAAc;IAAK;IAErE,MAAMC,sBAAsB,OAAOC;QAC/B,IAAI;YACA,MAAMC,MAAM,MAAMlB,QAAQiB;YAC1B,MAAME,UAAU,MAAMP,QAAQQ,MAAM,CAACH,MAAMC,KAAK,CAAC,CAACb;YAClD,MAAMc,QAAQE,SAAS;QAC3B,EAAE,OAAOC,OAAO;YACZC,UAAG,CAACD,KAAK,CAACE,OAAOF;QACrB;IACJ;IAEA,IAAI,CAACjB,OAAO;QACRkB,UAAG,CAACE,IAAI,CAAC,CAAC,qBAAqB,EAAEhB,cAAc;QAC/C,MAAMiB,QAAQ,MAAMC,IAAAA,UAAI,EAAClB;QACzB,MAAMmB,QAAQC,GAAG,CAACH,MAAMI,GAAG,CAACd;QAC5B;IACJ;IAEAO,UAAG,CAACE,IAAI,CAAC,CAAC,+BAA+B,EAAEhB,cAAc;IAEzDsB,WAAWzB,QAAQ,OAAO0B;QACtBT,UAAG,CAACU,KAAK,CAAC,OAAO,CAAC,UAAU,EAAED,MAAM;QACpC,MAAMhB,oBAAoBgB;IAC9B;IAEA,0DAA0D,GAC1D,IAAIE,QAAQC,GAAG,CAACC,QAAQ,KAAK,QAAQ;QACjC,MAAM,IAAIR,QAAc,KAAO;IACnC;AACJ;AAEA,SAASG,WAAWzB,MAAc,EAAE+B,QAAyC;IACzE,MAAMC,cAAc,IAAIC,OAAO,CAAC,aAAa,EAAE7B,gCAAe,CAACC,IAAI,CAAC,KAAK,EAAE,CAAC;IAC5E,MAAM6B,UAAUC,iBAAQ,CAACpC,KAAK,CAACC,QAAQ;QACnCoC,SAAS,CAACV,MAAMW,QAAU,CAAC,EAACA,kBAAAA,4BAAAA,MAAOC,MAAM,OAAM,CAACN,YAAYO,IAAI,CAACb;QACjEc,eAAe;IACnB;IACAN,QAAQO,EAAE,CAAC,OAAOV;IAClBG,QAAQO,EAAE,CAAC,UAAUV;AACzB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"file-rules.d.ts","sourceRoot":"","sources":["../../../src/webpack/__mocks__/file-rules.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAqBtC,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAmDjD,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/webpack/__mocks__/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { RuleSetRule } from 'webpack';
|
|
2
|
-
export type StyleRule = RuleSetRule & {
|
|
3
|
-
use: (string | object)[];
|
|
4
|
-
};
|
|
5
|
-
export declare const styleRules: Record<string, StyleRule>;
|
|
6
|
-
export declare const webComponentStyleRules: Record<string, StyleRule>;
|
|
7
|
-
export declare const productionStyleRules: Record<string, StyleRule>;
|
|
8
|
-
//# sourceMappingURL=style-rules.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"style-rules.d.ts","sourceRoot":"","sources":["../../../src/webpack/__mocks__/style-rules.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,MAAM,MAAM,SAAS,GAAG,WAAW,GAAG;IAAE,GAAG,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAA;CAAE,CAAC;AAEnE,eAAO,MAAM,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CA4EhD,CAAC;AAEF,eAAO,MAAM,sBAAsB,2BAMlC,CAAC;AAEF,eAAO,MAAM,oBAAoB,2BAUhC,CAAC"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { Configuration } from 'webpack';
|
|
2
|
-
import { Context, Overrides } from './types';
|
|
3
|
-
type Result = Pick<Configuration, 'cache'> | undefined;
|
|
4
|
-
export declare function cacheConfig(context: Context, _: Overrides): Result;
|
|
5
|
-
export {};
|
|
6
|
-
//# sourceMappingURL=cache-config.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cache-config.d.ts","sourceRoot":"","sources":["../../../src/webpack/configs/cache-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAGxC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAE7C,KAAK,MAAM,GAAG,IAAI,CAAC,aAAa,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;AAEvD,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,SAAS,GAAG,MAAM,CAiBlE"}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "cacheConfig", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return cacheConfig;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _utils = require("../../utils");
|
|
12
|
-
const _utils1 = require("../utils");
|
|
13
|
-
function cacheConfig(context, _) {
|
|
14
|
-
const { embed, isProduction, isWebComponent } = context;
|
|
15
|
-
if (isProduction) {
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
return (0, _utils1.featureCohort)([
|
|
19
|
-
2,
|
|
20
|
-
5
|
|
21
|
-
], ()=>{
|
|
22
|
-
const packageName = (0, _utils.getPackageName)();
|
|
23
|
-
_utils.log.info('Persistent cache is active');
|
|
24
|
-
return {
|
|
25
|
-
cache: {
|
|
26
|
-
type: 'filesystem',
|
|
27
|
-
name: isWebComponent ? `${packageName}__${embed ? 'light' : 'full'}` : packageName,
|
|
28
|
-
profile: true
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
//# sourceMappingURL=cache-config.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/webpack/configs/cache-config.ts"],"sourcesContent":["import { Configuration } from 'webpack';\nimport { getPackageName, log } from '../../utils';\nimport { featureCohort } from '../utils';\nimport { Context, Overrides } from './types';\n\ntype Result = Pick<Configuration, 'cache'> | undefined;\n\nexport function cacheConfig(context: Context, _: Overrides): Result {\n const { embed, isProduction, isWebComponent } = context;\n if (isProduction) {\n return;\n }\n\n return featureCohort([2, 5], () => {\n const packageName = getPackageName();\n log.info('Persistent cache is active');\n return {\n cache: {\n type: 'filesystem',\n name: isWebComponent ? `${packageName}__${embed ? 'light' : 'full'}` : packageName,\n profile: true,\n },\n };\n });\n}\n"],"names":["cacheConfig","context","_","embed","isProduction","isWebComponent","featureCohort","packageName","getPackageName","log","info","cache","type","name","profile"],"mappings":";;;;+BAOgBA;;;eAAAA;;;uBANoB;wBACN;AAKvB,SAASA,YAAYC,OAAgB,EAAEC,CAAY;IACtD,MAAM,EAAEC,KAAK,EAAEC,YAAY,EAAEC,cAAc,EAAE,GAAGJ;IAChD,IAAIG,cAAc;QACd;IACJ;IAEA,OAAOE,IAAAA,qBAAa,EAAC;QAAC;QAAG;KAAE,EAAE;QACzB,MAAMC,cAAcC,IAAAA,qBAAc;QAClCC,UAAG,CAACC,IAAI,CAAC;QACT,OAAO;YACHC,OAAO;gBACHC,MAAM;gBACNC,MAAMR,iBAAiB,GAAGE,YAAY,EAAE,EAAEJ,QAAQ,UAAU,QAAQ,GAAGI;gBACvEO,SAAS;YACb;QACJ;IACJ;AACJ"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"feature-cohort.d.ts","sourceRoot":"","sources":["../../../src/webpack/utils/feature-cohort.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,GAAG,SAAS,CAS7F"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "featureCohort", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return featureCohort;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _username = require("username");
|
|
12
|
-
const _utils = require("../../utils");
|
|
13
|
-
const _hashmod = require("./hash-mod");
|
|
14
|
-
function featureCohort([limit, total], fn) {
|
|
15
|
-
if (limit >= total) {
|
|
16
|
-
_utils.log.warning('featureCohort: feature always active');
|
|
17
|
-
}
|
|
18
|
-
const mod = (0, _hashmod.hashMod)(total);
|
|
19
|
-
var _username1;
|
|
20
|
-
const cohort = mod((_username1 = (0, _username.sync)()) !== null && _username1 !== void 0 ? _username1 : '');
|
|
21
|
-
if (cohort < limit) {
|
|
22
|
-
return fn();
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
//# sourceMappingURL=feature-cohort.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/webpack/utils/feature-cohort.ts"],"sourcesContent":["import { sync as username } from 'username';\n\nimport { log } from '../../utils';\n\nimport { hashMod } from './hash-mod';\n\n/**\n * Allows to enable feature for part of the auditory based on stable trait (username).\n */\nexport function featureCohort<T>([limit, total]: [number, number], fn: () => T): T | undefined {\n if (limit >= total) {\n log.warning('featureCohort: feature always active');\n }\n const mod = hashMod(total);\n const cohort = mod(username() ?? '');\n if (cohort < limit) {\n return fn();\n }\n}\n"],"names":["featureCohort","limit","total","fn","log","warning","mod","hashMod","username","cohort"],"mappings":";;;;+BASgBA;;;eAAAA;;;0BATiB;uBAEb;yBAEI;AAKjB,SAASA,cAAiB,CAACC,OAAOC,MAAwB,EAAEC,EAAW;IAC1E,IAAIF,SAASC,OAAO;QAChBE,UAAG,CAACC,OAAO,CAAC;IAChB;IACA,MAAMC,MAAMC,IAAAA,gBAAO,EAACL;QACDM;IAAnB,MAAMC,SAASH,IAAIE,CAAAA,aAAAA,IAAAA,cAAQ,iBAARA,wBAAAA,aAAc;IACjC,IAAIC,SAASR,OAAO;QAChB,OAAOE;IACX;AACJ"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Returns a `hashMod` function that will return an integer hash of a string
|
|
3
|
-
* modded by `buckets`.
|
|
4
|
-
*
|
|
5
|
-
* @param {Number} buckets
|
|
6
|
-
* @return {Function}
|
|
7
|
-
*/
|
|
8
|
-
export declare function hashMod(buckets: number): (string: string) => number;
|
|
9
|
-
//# sourceMappingURL=hash-mod.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hash-mod.d.ts","sourceRoot":"","sources":["../../../src/webpack/utils/hash-mod.ts"],"names":[],"mappings":"AAMA;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,OAAO,EAAE,MAAM,IAClB,QAAQ,MAAM,YAGlC"}
|
|
@@ -1,39 +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
|
-
* Returns a `hashMod` function that will return an integer hash of a string
|
|
7
|
-
* modded by `buckets`.
|
|
8
|
-
*
|
|
9
|
-
* @param {Number} buckets
|
|
10
|
-
* @return {Function}
|
|
11
|
-
*/ "use strict";
|
|
12
|
-
Object.defineProperty(exports, "__esModule", {
|
|
13
|
-
value: true
|
|
14
|
-
});
|
|
15
|
-
Object.defineProperty(exports, "hashMod", {
|
|
16
|
-
enumerable: true,
|
|
17
|
-
get: function() {
|
|
18
|
-
return hashMod;
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
function hashMod(buckets) {
|
|
22
|
-
return function(string) {
|
|
23
|
-
return integerHash(string) % buckets;
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Return the integer hash of a `string`.
|
|
28
|
-
*
|
|
29
|
-
* http://stackoverflow.com/questions/2624192/good-hash-function-for-strings
|
|
30
|
-
*
|
|
31
|
-
* @param {String} string
|
|
32
|
-
* @returns {Number}
|
|
33
|
-
*/ function integerHash(string) {
|
|
34
|
-
return (string + '').split('').reduce(function(memo, item) {
|
|
35
|
-
return memo * 31 * item.charCodeAt(0) % 982451653;
|
|
36
|
-
}, 7);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
//# sourceMappingURL=hash-mod.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/webpack/utils/hash-mod.ts"],"sourcesContent":["/*\n * salvaged from https://github.com/segment-boneyard/hash-mod\n * 1. recent code from repo never got into npm registry\n * 2. no types in DefinitelyTyped\n */\n\n/**\n * Returns a `hashMod` function that will return an integer hash of a string\n * modded by `buckets`.\n *\n * @param {Number} buckets\n * @return {Function}\n */\nexport function hashMod(buckets: number) {\n return function (string: string) {\n return integerHash(string) % buckets;\n };\n}\n\n/**\n * Return the integer hash of a `string`.\n *\n * http://stackoverflow.com/questions/2624192/good-hash-function-for-strings\n *\n * @param {String} string\n * @returns {Number}\n */\nfunction integerHash(string: string) {\n return (string + '').split('').reduce(function (memo, item) {\n return (memo * 31 * item.charCodeAt(0)) % 982451653;\n }, 7);\n}\n"],"names":["hashMod","buckets","string","integerHash","split","reduce","memo","item","charCodeAt"],"mappings":"AAAA;;;;CAIC,GAED;;;;;;CAMC;;;;+BACeA;;;eAAAA;;;AAAT,SAASA,QAAQC,OAAe;IACnC,OAAO,SAAUC,MAAc;QAC3B,OAAOC,YAAYD,UAAUD;IACjC;AACJ;AAEA;;;;;;;CAOC,GACD,SAASE,YAAYD,MAAc;IAC/B,OAAO,AAACA,CAAAA,SAAS,EAAC,EAAGE,KAAK,CAAC,IAAIC,MAAM,CAAC,SAAUC,IAAI,EAAEC,IAAI;QACtD,OAAO,AAACD,OAAO,KAAKC,KAAKC,UAAU,CAAC,KAAM;IAC9C,GAAG;AACP"}
|