@servicetitan/restrict-imports 33.1.1 → 34.0.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/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export type { RawConfig as Config, RawEntry as Entry } from './config';
2
- export type { RestrictionZone } from './restrict-imports';
3
2
  export { restrictImports } from './restrict-imports';
3
+ export type { RestrictionZone } from './restrict-imports';
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,SAAS,IAAI,MAAM,EAAE,QAAQ,IAAI,KAAK,EAAE,MAAM,UAAU,CAAC;AACvE,YAAY,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,SAAS,IAAI,MAAM,EAAE,QAAQ,IAAI,KAAK,EAAE,MAAM,UAAU,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,YAAY,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC"}
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export type { RawConfig as Config, RawEntry as Entry } from './config';\nexport type { RestrictionZone } from './restrict-imports';\nexport { restrictImports } from './restrict-imports';\n"],"names":["restrictImports"],"mappings":";;;;+BAESA;;;eAAAA,gCAAe;;;iCAAQ"}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export type { RawConfig as Config, RawEntry as Entry } from './config';\nexport { restrictImports } from './restrict-imports';\nexport type { RestrictionZone } from './restrict-imports';\n"],"names":["restrictImports"],"mappings":";;;;+BACSA;;;eAAAA,gCAAe;;;iCAAQ"}
@@ -63,7 +63,7 @@ function getAllow(c) {
63
63
  e.allow
64
64
  ]));
65
65
  return (name)=>{
66
- var _m_get, _ref;
66
+ var _ref, _m_get;
67
67
  return (_ref = (_m_get = m.get(name)) !== null && _m_get !== void 0 ? _m_get : m.get('*')) !== null && _ref !== void 0 ? _ref : [];
68
68
  };
69
69
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/restrict-imports.ts"],"sourcesContent":["import { canonicalizeConfig, Config, RawConfig, validateRawConfig } from './config';\n\n/**\n * @param {string} base an absolute path\n * @param {Array<string>} modules\n * @param {Object} [config] describes import restrictions between modules\n *\n * @example\n * [\n * // 'common' is self-containing, imports from other modules is restricted\n * { name: 'common' },\n *\n * // 'ach' can import only from 'common' module\n * { name: 'ach-modal', allow: 'common' },\n *\n * // both 'accounting' and 'onboarding' can import only from 'common' and 'ach-modal' modules\n * { name: 'accounting', allow: ['common', 'ach-modal'] },\n * { name: 'onboarding', allow: ['common', 'ach-modal'] },\n *\n * // '*' describes any module which has no a special config entry\n * { name: '*', allow: 'common' },\n *\n * // 'header' can import from every module, except for 'settings'\n * { name: 'header', allow: '*' },\n *\n * // 'settings' can import from every module\n * { name: 'settings', allow: '*' },\n * ]\n *\n * @description Config should follow the next rules:\n * 1. The only available mask for both `name` and `allow` fields is '*'\n * 2. Order of entries is important to avoid circular dependencies between modules, module's dependency should be described *above* the module description. In the example, the 'common' module should be described *above* other modules. This rule also applies to the '*' mask, it should be described *before* it is using in other config entries.\n */\n\nexport function restrictImports(\n base: string,\n modules: string[],\n config?: RawConfig\n): RestrictionZone[] {\n const validationError = validateRawConfig(config);\n if (validationError) {\n throw new Error(validationError);\n }\n\n return restrictImports_(base, modules, canonicalizeConfig(config));\n}\n\n// suppose we have '*' entry in the `config`\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport function restrictImports_(base: string, modules: string[], config: Config) {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n const getAllow_ = getAllow(config);\n\n return modules.reduce<RestrictionZone[]>((acc, name) => {\n const allow = getAllow_(name);\n if (allow !== '*') {\n return [...acc, allowZone(base, name, allow)];\n }\n\n const disallow = getDisallow(config, name);\n if (disallow.length > 0) {\n return [...acc, disallowZone(base, name, disallow)];\n }\n\n return acc;\n }, []);\n}\n\nexport function getAllow(c: Config) {\n const m = new Map(c.map(e => [e.name, e.allow]));\n\n return (name: string) => m.get(name) ?? m.get('*') ?? [];\n}\n\nexport function getDisallow(c: Config, name: string) {\n const names = c.map(c => c.name);\n const index = names.indexOf(name);\n\n return names.slice(index + 1);\n}\n\nexport function allowZone(base: string, dirName: string, allow: string[] = []): RestrictionZone {\n return {\n target: base + dirName,\n from: `${base}**/*`,\n except: [`${base}${toGlobList([dirName, ...allow])}/**/*`],\n };\n}\n\nexport function disallowZone(base: string, dirName: string, disallow: string[]): RestrictionZone {\n return {\n target: base + dirName,\n from: `${base}${toGlobList(disallow)}/**/*`,\n };\n}\n\nconst toGlobList = (items: string[]) => {\n if (!items.length) {\n return '';\n }\n\n const uniqueItems = Array.from(new Set(items));\n\n if (uniqueItems.length === 1) {\n return uniqueItems[0];\n }\n\n return `{${uniqueItems.join(',')}}`;\n};\n\nexport interface RestrictionZone {\n target: string;\n from: string;\n except?: string[];\n}\n"],"names":["allowZone","disallowZone","getAllow","getDisallow","restrictImports","restrictImports_","base","modules","config","validationError","validateRawConfig","Error","canonicalizeConfig","getAllow_","reduce","acc","name","allow","disallow","length","c","m","Map","map","e","get","names","index","indexOf","slice","dirName","target","from","except","toGlobList","items","uniqueItems","Array","Set","join"],"mappings":";;;;;;;;;;;QAiFgBA;eAAAA;;QAQAC;eAAAA;;QArBAC;eAAAA;;QAMAC;eAAAA;;QAxCAC;eAAAA;;QAeAC;eAAAA;;;wBAjDyD;AAkClE,SAASD,gBACZE,IAAY,EACZC,OAAiB,EACjBC,MAAkB;IAElB,MAAMC,kBAAkBC,IAAAA,yBAAiB,EAACF;IAC1C,IAAIC,iBAAiB;QACjB,MAAM,IAAI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AAE,KAAK,CAAC;SAAC;IAC9D;AACJ;AAEO,SAAShB,aAAaK,IAAY,EAAEwB,OAAe,EAAEZ,QAAkB;IAC1E,OAAO;QACHa,QAAQzB,OAAOwB;QACfE,MAAM,GAAG1B,OAAO4B,WAAWhB,UAAU,KAAK,CAAC;IAC/C;AACJ;AAEA,MAAMgB,aAAa,CAACC;IAChB,IAAI,CAACA,MAAMhB,MAAM,EAAE;QACf,OAAO;IACX;IAEA,MAAMiB,cAAcC,MAAML,IAAI,CAAC,IAAIM,IAAIH;IAEvC,IAAIC,YAAYjB,MAAM,KAAK,GAAG;QAC1B,OAAOiB,WAAW,CAAC,EAAE;IACzB;IAEA,OAAO,CAAC,CAAC,EAAEA,YAAYG,IAAI,CAAC,KAAK,CAAC,CAAC;AACvC"}
1
+ {"version":3,"sources":["../src/restrict-imports.ts"],"sourcesContent":["import { canonicalizeConfig, Config, RawConfig, validateRawConfig } from './config';\n\n/**\n * @param {string} base an absolute path\n * @param {Array<string>} modules\n * @param {Object} [config] describes import restrictions between modules\n *\n * @example\n * [\n * // 'common' is self-containing, imports from other modules is restricted\n * { name: 'common' },\n *\n * // 'ach' can import only from 'common' module\n * { name: 'ach-modal', allow: 'common' },\n *\n * // both 'accounting' and 'onboarding' can import only from 'common' and 'ach-modal' modules\n * { name: 'accounting', allow: ['common', 'ach-modal'] },\n * { name: 'onboarding', allow: ['common', 'ach-modal'] },\n *\n * // '*' describes any module which has no a special config entry\n * { name: '*', allow: 'common' },\n *\n * // 'header' can import from every module, except for 'settings'\n * { name: 'header', allow: '*' },\n *\n * // 'settings' can import from every module\n * { name: 'settings', allow: '*' },\n * ]\n *\n * @description Config should follow the next rules:\n * 1. The only available mask for both `name` and `allow` fields is '*'\n * 2. Order of entries is important to avoid circular dependencies between modules, module's dependency should be described *above* the module description. In the example, the 'common' module should be described *above* other modules. This rule also applies to the '*' mask, it should be described *before* it is using in other config entries.\n */\n\nexport function restrictImports(\n base: string,\n modules: string[],\n config?: RawConfig\n): RestrictionZone[] {\n const validationError = validateRawConfig(config);\n if (validationError) {\n throw new Error(validationError);\n }\n\n return restrictImports_(base, modules, canonicalizeConfig(config));\n}\n\n// suppose we have '*' entry in the `config`\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport function restrictImports_(base: string, modules: string[], config: Config) {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n const getAllow_ = getAllow(config);\n\n return modules.reduce<RestrictionZone[]>((acc, name) => {\n const allow = getAllow_(name);\n if (allow !== '*') {\n return [...acc, allowZone(base, name, allow)];\n }\n\n const disallow = getDisallow(config, name);\n if (disallow.length > 0) {\n return [...acc, disallowZone(base, name, disallow)];\n }\n\n return acc;\n }, []);\n}\n\nexport function getAllow(c: Config) {\n const m = new Map(c.map(e => [e.name, e.allow]));\n\n return (name: string) => m.get(name) ?? m.get('*') ?? [];\n}\n\nexport function getDisallow(c: Config, name: string) {\n const names = c.map(c => c.name);\n const index = names.indexOf(name);\n\n return names.slice(index + 1);\n}\n\nexport function allowZone(base: string, dirName: string, allow: string[] = []): RestrictionZone {\n return {\n target: base + dirName,\n from: `${base}**/*`,\n except: [`${base}${toGlobList([dirName, ...allow])}/**/*`],\n };\n}\n\nexport function disallowZone(base: string, dirName: string, disallow: string[]): RestrictionZone {\n return {\n target: base + dirName,\n from: `${base}${toGlobList(disallow)}/**/*`,\n };\n}\n\nconst toGlobList = (items: string[]) => {\n if (!items.length) {\n return '';\n }\n\n const uniqueItems = Array.from(new Set(items));\n\n if (uniqueItems.length === 1) {\n return uniqueItems[0];\n }\n\n return `{${uniqueItems.join(',')}}`;\n};\n\nexport interface RestrictionZone {\n target: string;\n from: string;\n except?: string[];\n}\n"],"names":["allowZone","disallowZone","getAllow","getDisallow","restrictImports","restrictImports_","base","modules","config","validationError","validateRawConfig","Error","canonicalizeConfig","getAllow_","reduce","acc","name","allow","disallow","length","c","m","Map","map","e","get","names","index","indexOf","slice","dirName","target","from","except","toGlobList","items","uniqueItems","Array","Set","join"],"mappings":";;;;;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U,MAAMG,KAAK,CAACF,QAAQ;AAC/B;AAEO,SAAS3B,UAAUM,IAAY,EAAEwB,OAAe,EAAEb,QAAkB,EAAE;IACzE,OAAO;QACHc,QAAQzB,OAAOwB;QACfE,MAAM,GAAG1B,KAAK,IAAI,CAAC;QACnB2B,QAAQ;YAAC,GAAG3B,OAAO4B,WAAW;gBAACJ;mBAAYb;aAAM,EAAE,KAAK,CAAC;SAAC;IAC9D;AACJ;AAEO,SAAShB,aAAaK,IAAY,EAAEwB,OAAe,EAAEZ,QAAkB;IAC1E,OAAO;QACHa,QAAQzB,OAAOwB;QACfE,MAAM,GAAG1B,OAAO4B,WAAWhB,UAAU,KAAK,CAAC;IAC/C;AACJ;AAEA,MAAMgB,aAAa,CAACC;IAChB,IAAI,CAACA,MAAMhB,MAAM,EAAE;QACf,OAAO;IACX;IAEA,MAAMiB,cAAcC,MAAML,IAAI,CAAC,IAAIM,IAAIH;IAEvC,IAAIC,YAAYjB,MAAM,KAAK,GAAG;QAC1B,OAAOiB,WAAW,CAAC,EAAE;IACzB;IAEA,OAAO,CAAC,CAAC,EAAEA,YAAYG,IAAI,CAAC,KAAK,CAAC,CAAC;AACvC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@servicetitan/restrict-imports",
3
- "version": "33.1.1",
4
- "description": "",
3
+ "version": "34.0.0",
4
+ "description": "Webpack plugin to enforce import restrictions between modules",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/servicetitan/uikit.git",
@@ -20,5 +20,5 @@
20
20
  "cli": {
21
21
  "webpack": false
22
22
  },
23
- "gitHead": "36ff4078b07d6c86bdf968b7f8b3c0adbe03fd4c"
23
+ "gitHead": "e193dc22703963f67099874a24de535d0696b6e2"
24
24
  }
@@ -1,10 +1,10 @@
1
1
  import { Allow, Config, RawConfig } from '../config';
2
2
  import {
3
- getAllow,
4
- restrictImports,
5
3
  allowZone,
6
- getDisallow,
7
4
  disallowZone,
5
+ getAllow,
6
+ getDisallow,
7
+ restrictImports,
8
8
  } from '../restrict-imports';
9
9
 
10
10
  describe('restrictImports()', () => {
package/src/index.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export type { RawConfig as Config, RawEntry as Entry } from './config';
2
- export type { RestrictionZone } from './restrict-imports';
3
2
  export { restrictImports } from './restrict-imports';
3
+ export type { RestrictionZone } from './restrict-imports';