@teambit/dependencies 1.0.785 → 1.0.787
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/files-dependency-builder/build-tree.js +1 -1
- package/dist/files-dependency-builder/build-tree.js.map +1 -1
- package/dist/files-dependency-builder/dependency-tree/index.d.ts +1 -1
- package/dist/files-dependency-builder/dependency-tree/index.js +7 -7
- package/dist/files-dependency-builder/dependency-tree/index.js.map +1 -1
- package/dist/files-dependency-builder/dependency-tree/index.spec.js +73 -73
- package/dist/files-dependency-builder/dependency-tree/index.spec.js.map +1 -1
- package/dist/files-dependency-builder/filing-cabinet/index.spec.js +1 -1
- package/dist/files-dependency-builder/filing-cabinet/index.spec.js.map +1 -1
- package/dist/files-dependency-builder/generate-tree-madge.d.ts +1 -1
- package/dist/files-dependency-builder/generate-tree-madge.js +5 -5
- package/dist/files-dependency-builder/generate-tree-madge.js.map +1 -1
- package/dist/files-dependency-builder/precinct/index.d.ts +1 -1
- package/dist/files-dependency-builder/precinct/index.js +2 -2
- package/dist/files-dependency-builder/precinct/index.js.map +1 -1
- package/dist/files-dependency-builder/precinct/index.spec.js +19 -19
- package/dist/files-dependency-builder/precinct/index.spec.js.map +1 -1
- package/files-dependency-builder/build-tree.ts +1 -1
- package/files-dependency-builder/dependency-tree/index.spec.ts +73 -73
- package/files-dependency-builder/dependency-tree/index.ts +7 -7
- package/files-dependency-builder/filing-cabinet/index.spec.ts +1 -1
- package/files-dependency-builder/generate-tree-madge.ts +5 -5
- package/files-dependency-builder/precinct/index.spec.ts +19 -19
- package/files-dependency-builder/precinct/index.ts +2 -2
- package/package.json +8 -8
- /package/dist/{preview-1760566720786.js → preview-1760636469189.js} +0 -0
|
@@ -253,7 +253,7 @@ const normalizeDeps = (deps, includeCore) => {
|
|
|
253
253
|
const normalizedDeps = Array.isArray(deps) ? deps : Object.keys(deps);
|
|
254
254
|
return includeCore ? normalizedDeps : normalizedDeps.filter(d => !(0, _module().isBuiltin)(d));
|
|
255
255
|
};
|
|
256
|
-
const getDepsFromFile = (filename, options) => {
|
|
256
|
+
const getDepsFromFile = async (filename, options) => {
|
|
257
257
|
const normalizedOptions = assign({
|
|
258
258
|
includeCore: true
|
|
259
259
|
}, options || {});
|
|
@@ -268,7 +268,7 @@ const getDepsFromFile = (filename, options) => {
|
|
|
268
268
|
return [];
|
|
269
269
|
}
|
|
270
270
|
debug('module type: ', fileInfo.type);
|
|
271
|
-
const deps = detective(fileInfo.ast, normalizedOptions[fileInfo.type]);
|
|
271
|
+
const deps = await detective(fileInfo.ast, normalizedOptions[fileInfo.type]);
|
|
272
272
|
return normalizeDeps(deps, normalizedOptions?.includeCore);
|
|
273
273
|
};
|
|
274
274
|
const precinct = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_fsExtra","data","_interopRequireDefault","require","_path","_module","_moduleDefinition","_nodeSourceWalk","_detectiveAmd","_detectiveStylus","_nodeDepsDetectors","_stylingDepsDetectors","_stylingDepsDetectors2","_stylingDepsDetectors3","_stylingDepsDetectors4","_typescriptDepsDetectors","_dependencyResolver","e","__esModule","default","jsExt","extToType","typeToDetective","css","detectiveCss","sass","detectiveSass","less","detectiveLess","scss","detectiveScss","stylus","detectiveStylus","ts","detectiveTypeScript","commonjs","detectiveEs6","es6","amd","detectiveAmd","debug","detectorHook","DetectorHook","assign","o1","o2","key","hasOwnProperty","getFileInfo","filename","ext","path","extname","content","fs","readFileSync","type","ast","getDetector","fileInfo","options","normalizedOptions","envDetectors","detector","isSupported","detect","detective","jsx","undefined","getJsDetector","includes","walker","Walker","parse","message","useContent","getModuleType","fromSource","normalizeDeps","deps","includeCore","normalizedDeps","Array","isArray","Object","keys","filter","d","isBuiltin","getDepsFromFile","startsWith","precinct","paperwork","_default","exports"],"sources":["index.ts"],"sourcesContent":["/**\n * this file had been forked from https://github.com/dependents/node-precinct\n */\nimport fs from 'fs-extra';\nimport path from 'path';\n// @ts-ignore we currently have @types/node as v12, and this is available > 16. once updated, remove the ts-ignore\nimport { isBuiltin } from 'module';\n\nimport getModuleType from 'module-definition';\nimport Walker from 'node-source-walk';\n\nimport detectiveAmd from 'detective-amd';\nimport detectiveStylus from 'detective-stylus';\n\nimport detectiveEs6 from '@teambit/node.deps-detectors.detective-es6';\nimport detectiveCss from '@teambit/styling.deps-detectors.detective-css';\nimport detectiveLess from '@teambit/styling.deps-detectors.detective-less';\nimport detectiveSass from '@teambit/styling.deps-detectors.detective-sass';\nimport detectiveScss from '@teambit/styling.deps-detectors.detective-scss';\nimport detectiveTypeScript from '@teambit/typescript.deps-detectors.detective-typescript';\n\nimport type { DependencyDetector } from '@teambit/dependency-resolver';\nimport { DetectorHook } from '@teambit/dependency-resolver';\n\n/**\n * The file info object.\n * - `ext` is the file extension.\n * - `content` is the input file content.\n * - `type` is the parsed file type from ext or content.\n * - `ast` is the eventually consumed content by the corresponding detective.\n */\ntype FileInfo = {\n ext: string;\n content: string | object;\n type: string;\n ast: any;\n filename: string;\n};\n\ntype Options = {\n envDetectors?: DependencyDetector[];\n useContent?: boolean;\n includeCore?: boolean;\n type?: string;\n [lang: string]: any;\n};\n\ntype BuiltinDeps = string[] | Record<string, any>;\ntype Detective = (fileContent: string, options?: any) => BuiltinDeps;\n\nconst jsExt = ['.js', '.jsx', '.cjs', '.mjs'];\n\nconst extToType = {\n '.css': 'css',\n '.sass': 'sass',\n '.less': 'less',\n '.scss': 'scss',\n '.styl': 'stylus',\n '.mts': 'ts',\n '.cts': 'ts',\n '.ts': 'ts',\n '.tsx': 'ts',\n};\n\nconst typeToDetective: Record<string, Detective> = {\n css: detectiveCss,\n sass: detectiveSass,\n less: detectiveLess,\n scss: detectiveScss,\n stylus: detectiveStylus,\n ts: detectiveTypeScript,\n commonjs: detectiveEs6,\n es6: detectiveEs6,\n amd: detectiveAmd,\n};\n\nconst debug = require('debug')('precinct');\n\nconst detectorHook = new DetectorHook();\n\nconst assign = (o1, o2) => {\n // eslint-disable-next-line\n for (const key in o2) {\n // eslint-disable-next-line\n if (o2.hasOwnProperty(key)) {\n o1[key] = o2[key];\n }\n }\n\n return o1;\n};\n\n/**\n * Get file info from the given file path.\n */\nconst getFileInfo = (filename: string): FileInfo => {\n const ext = path.extname(filename);\n const content = fs.readFileSync(filename, 'utf8');\n return {\n ext,\n content,\n // determined later\n type: '',\n // initialized with the content\n ast: content,\n filename,\n };\n};\n\n/**\n * Get the non-JS detective for the given file info.\n * The type of the file would be determined as well.\n * Return undefined if no proper detective found, perhaps it's plain\n * JavaScript or unknown content. We can deal with it later.\n */\nconst getDetector = (fileInfo: FileInfo, options?: Options): Detective | undefined => {\n const { ext, filename } = fileInfo;\n const normalizedOptions: Options = options || {};\n\n // from env detectors\n if (options?.envDetectors) {\n for (const detector of options.envDetectors) {\n if (detector.isSupported({ ext, filename })) {\n fileInfo.type = detector.type || '';\n return detector.detect as Detective;\n }\n }\n }\n\n // from builtin detectors\n // - check `fileInfo.type` first to support `precinct(content, { type })`\n const type = fileInfo.type || extToType[ext];\n if (typeToDetective[type]) {\n const detective = typeToDetective[type];\n fileInfo.type = type;\n // special logic for tsx files\n if (ext === '.tsx') {\n if (!normalizedOptions.ts) normalizedOptions.ts = {};\n normalizedOptions.ts.jsx = true;\n }\n return detective;\n }\n\n // from global detector hook (legacy)\n if (detectorHook.isSupported(ext, filename)) {\n const detector = detectorHook.getDetector(ext, filename);\n if (detector) {\n fileInfo.type = ext;\n typeToDetective[ext] = detector.detect as Detective;\n return detector.detect as Detective;\n }\n }\n\n return undefined;\n};\n\n/**\n * Get the JS detective (amd/es6/cjs) for the given file info.\n * The type and ast of the file would be determined as well.\n */\nconst getJsDetector = (fileInfo: FileInfo, options?: Options): Detective | undefined => {\n if (!jsExt.includes(fileInfo.ext)) {\n return undefined;\n }\n\n if (typeof fileInfo.content !== 'object') {\n const walker = new Walker();\n try {\n fileInfo.ast = walker.parse(fileInfo.content);\n } catch (e: any) {\n debug('could not parse content: %s', e.message);\n throw e;\n }\n }\n\n const useContent = options?.useContent;\n const type = useContent ? getModuleType.fromSource(fileInfo.content) : getModuleType.fromSource(fileInfo.ast);\n const detector = typeToDetective[type];\n fileInfo.type = type;\n\n return detector;\n};\n\n/**\n * Normalize the deps into an array.\n */\nconst normalizeDeps = (deps: BuiltinDeps, includeCore?: boolean): string[] => {\n const normalizedDeps = Array.isArray(deps) ? deps : Object.keys(deps);\n return includeCore ? normalizedDeps : normalizedDeps.filter((d) => !isBuiltin(d));\n};\n\nconst getDepsFromFile = (filename: string, options?: Options): string[] => {\n const normalizedOptions: Options = assign({ includeCore: true }, options || {});\n const fileInfo = getFileInfo(filename);\n if (\n typeof fileInfo.content === 'string' &&\n (fileInfo.content.startsWith('// @bit-no-check') || fileInfo.content.startsWith('/* @bit-no-check'))\n ) {\n debug(`skipping file ${filename}, it has a @bit-no-check comment`);\n return [];\n }\n\n const detective = getDetector(fileInfo, normalizedOptions) || getJsDetector(fileInfo, normalizedOptions);\n if (!detective) {\n debug(`skipping unsupported file ${filename}`);\n return [];\n }\n debug('module type: ', fileInfo.type);\n\n const deps = detective(fileInfo.ast, normalizedOptions[fileInfo.type]);\n\n return normalizeDeps(deps, normalizedOptions?.includeCore);\n};\n\nconst precinct = {\n paperwork: getDepsFromFile,\n};\n\nexport default precinct;\n"],"mappings":";;;;;;AAGA,SAAAA,SAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,QAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,MAAA;EAAA,MAAAH,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAC,KAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAI,QAAA;EAAA,MAAAJ,IAAA,GAAAE,OAAA;EAAAE,OAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAK,kBAA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K,SAAS,EAAE;IACd1B,KAAK,CAAC,6BAA6BS,QAAQ,EAAE,CAAC;IAC9C,OAAO,EAAE;EACX;EACAT,KAAK,CAAC,eAAe,EAAEmB,QAAQ,CAACH,IAAI,CAAC;EAErC,MAAMuB,IAAI,GAAGb,SAAS,CAACP,QAAQ,CAACF,GAAG,EAAEI,iBAAiB,CAACF,QAAQ,CAACH,IAAI,CAAC,CAAC;EAEtE,OAAOsB,aAAa,CAACC,IAAI,EAAElB,iBAAiB,EAAEmB,WAAW,CAAC;AAC5D,CAAC;AAED,MAAMW,QAAQ,GAAG;EACfC,SAAS,EAAEH;AACb,CAAC;AAAC,IAAAI,QAAA,GAAAC,OAAA,CAAA3E,OAAA,GAEawE,QAAQ","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_fsExtra","data","_interopRequireDefault","require","_path","_module","_moduleDefinition","_nodeSourceWalk","_detectiveAmd","_detectiveStylus","_nodeDepsDetectors","_stylingDepsDetectors","_stylingDepsDetectors2","_stylingDepsDetectors3","_stylingDepsDetectors4","_typescriptDepsDetectors","_dependencyResolver","e","__esModule","default","jsExt","extToType","typeToDetective","css","detectiveCss","sass","detectiveSass","less","detectiveLess","scss","detectiveScss","stylus","detectiveStylus","ts","detectiveTypeScript","commonjs","detectiveEs6","es6","amd","detectiveAmd","debug","detectorHook","DetectorHook","assign","o1","o2","key","hasOwnProperty","getFileInfo","filename","ext","path","extname","content","fs","readFileSync","type","ast","getDetector","fileInfo","options","normalizedOptions","envDetectors","detector","isSupported","detect","detective","jsx","undefined","getJsDetector","includes","walker","Walker","parse","message","useContent","getModuleType","fromSource","normalizeDeps","deps","includeCore","normalizedDeps","Array","isArray","Object","keys","filter","d","isBuiltin","getDepsFromFile","startsWith","precinct","paperwork","_default","exports"],"sources":["index.ts"],"sourcesContent":["/**\n * this file had been forked from https://github.com/dependents/node-precinct\n */\nimport fs from 'fs-extra';\nimport path from 'path';\n// @ts-ignore we currently have @types/node as v12, and this is available > 16. once updated, remove the ts-ignore\nimport { isBuiltin } from 'module';\n\nimport getModuleType from 'module-definition';\nimport Walker from 'node-source-walk';\n\nimport detectiveAmd from 'detective-amd';\nimport detectiveStylus from 'detective-stylus';\n\nimport detectiveEs6 from '@teambit/node.deps-detectors.detective-es6';\nimport detectiveCss from '@teambit/styling.deps-detectors.detective-css';\nimport detectiveLess from '@teambit/styling.deps-detectors.detective-less';\nimport detectiveSass from '@teambit/styling.deps-detectors.detective-sass';\nimport detectiveScss from '@teambit/styling.deps-detectors.detective-scss';\nimport detectiveTypeScript from '@teambit/typescript.deps-detectors.detective-typescript';\n\nimport type { DependencyDetector } from '@teambit/dependency-resolver';\nimport { DetectorHook } from '@teambit/dependency-resolver';\n\n/**\n * The file info object.\n * - `ext` is the file extension.\n * - `content` is the input file content.\n * - `type` is the parsed file type from ext or content.\n * - `ast` is the eventually consumed content by the corresponding detective.\n */\ntype FileInfo = {\n ext: string;\n content: string | object;\n type: string;\n ast: any;\n filename: string;\n};\n\ntype Options = {\n envDetectors?: DependencyDetector[];\n useContent?: boolean;\n includeCore?: boolean;\n type?: string;\n [lang: string]: any;\n};\n\ntype BuiltinDeps = string[] | Record<string, any>;\ntype Detective = (fileContent: string, options?: any) => BuiltinDeps;\n\nconst jsExt = ['.js', '.jsx', '.cjs', '.mjs'];\n\nconst extToType = {\n '.css': 'css',\n '.sass': 'sass',\n '.less': 'less',\n '.scss': 'scss',\n '.styl': 'stylus',\n '.mts': 'ts',\n '.cts': 'ts',\n '.ts': 'ts',\n '.tsx': 'ts',\n};\n\nconst typeToDetective: Record<string, Detective> = {\n css: detectiveCss,\n sass: detectiveSass,\n less: detectiveLess,\n scss: detectiveScss,\n stylus: detectiveStylus,\n ts: detectiveTypeScript,\n commonjs: detectiveEs6,\n es6: detectiveEs6,\n amd: detectiveAmd,\n};\n\nconst debug = require('debug')('precinct');\n\nconst detectorHook = new DetectorHook();\n\nconst assign = (o1, o2) => {\n // eslint-disable-next-line\n for (const key in o2) {\n // eslint-disable-next-line\n if (o2.hasOwnProperty(key)) {\n o1[key] = o2[key];\n }\n }\n\n return o1;\n};\n\n/**\n * Get file info from the given file path.\n */\nconst getFileInfo = (filename: string): FileInfo => {\n const ext = path.extname(filename);\n const content = fs.readFileSync(filename, 'utf8');\n return {\n ext,\n content,\n // determined later\n type: '',\n // initialized with the content\n ast: content,\n filename,\n };\n};\n\n/**\n * Get the non-JS detective for the given file info.\n * The type of the file would be determined as well.\n * Return undefined if no proper detective found, perhaps it's plain\n * JavaScript or unknown content. We can deal with it later.\n */\nconst getDetector = (fileInfo: FileInfo, options?: Options): Detective | undefined => {\n const { ext, filename } = fileInfo;\n const normalizedOptions: Options = options || {};\n\n // from env detectors\n if (options?.envDetectors) {\n for (const detector of options.envDetectors) {\n if (detector.isSupported({ ext, filename })) {\n fileInfo.type = detector.type || '';\n return detector.detect as Detective;\n }\n }\n }\n\n // from builtin detectors\n // - check `fileInfo.type` first to support `precinct(content, { type })`\n const type = fileInfo.type || extToType[ext];\n if (typeToDetective[type]) {\n const detective = typeToDetective[type];\n fileInfo.type = type;\n // special logic for tsx files\n if (ext === '.tsx') {\n if (!normalizedOptions.ts) normalizedOptions.ts = {};\n normalizedOptions.ts.jsx = true;\n }\n return detective;\n }\n\n // from global detector hook (legacy)\n if (detectorHook.isSupported(ext, filename)) {\n const detector = detectorHook.getDetector(ext, filename);\n if (detector) {\n fileInfo.type = ext;\n typeToDetective[ext] = detector.detect as Detective;\n return detector.detect as Detective;\n }\n }\n\n return undefined;\n};\n\n/**\n * Get the JS detective (amd/es6/cjs) for the given file info.\n * The type and ast of the file would be determined as well.\n */\nconst getJsDetector = (fileInfo: FileInfo, options?: Options): Detective | undefined => {\n if (!jsExt.includes(fileInfo.ext)) {\n return undefined;\n }\n\n if (typeof fileInfo.content !== 'object') {\n const walker = new Walker();\n try {\n fileInfo.ast = walker.parse(fileInfo.content);\n } catch (e: any) {\n debug('could not parse content: %s', e.message);\n throw e;\n }\n }\n\n const useContent = options?.useContent;\n const type = useContent ? getModuleType.fromSource(fileInfo.content) : getModuleType.fromSource(fileInfo.ast);\n const detector = typeToDetective[type];\n fileInfo.type = type;\n\n return detector;\n};\n\n/**\n * Normalize the deps into an array.\n */\nconst normalizeDeps = (deps: BuiltinDeps, includeCore?: boolean): string[] => {\n const normalizedDeps = Array.isArray(deps) ? deps : Object.keys(deps);\n return includeCore ? normalizedDeps : normalizedDeps.filter((d) => !isBuiltin(d));\n};\n\nconst getDepsFromFile = async (filename: string, options?: Options): Promise<string[]> => {\n const normalizedOptions: Options = assign({ includeCore: true }, options || {});\n const fileInfo = getFileInfo(filename);\n if (\n typeof fileInfo.content === 'string' &&\n (fileInfo.content.startsWith('// @bit-no-check') || fileInfo.content.startsWith('/* @bit-no-check'))\n ) {\n debug(`skipping file ${filename}, it has a @bit-no-check comment`);\n return [];\n }\n\n const detective = getDetector(fileInfo, normalizedOptions) || getJsDetector(fileInfo, normalizedOptions);\n if (!detective) {\n debug(`skipping unsupported file ${filename}`);\n return [];\n }\n debug('module type: ', fileInfo.type);\n\n const deps = await detective(fileInfo.ast, normalizedOptions[fileInfo.type]);\n\n return normalizeDeps(deps, normalizedOptions?.includeCore);\n};\n\nconst precinct = {\n paperwork: getDepsFromFile,\n};\n\nexport default precinct;\n"],"mappings":";;;;;;AAGA,SAAAA,SAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,QAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,MAAA;EAAA,MAAAH,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAC,KAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAI,QAAA;EAAA,MAAAJ,IAAA,GAAAE,OAAA;EAAAE,OAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAK,kBAAA;EAAA,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K,SAAS,EAAE;IACd1B,KAAK,CAAC,6BAA6BS,QAAQ,EAAE,CAAC;IAC9C,OAAO,EAAE;EACX;EACAT,KAAK,CAAC,eAAe,EAAEmB,QAAQ,CAACH,IAAI,CAAC;EAErC,MAAMuB,IAAI,GAAG,MAAMb,SAAS,CAACP,QAAQ,CAACF,GAAG,EAAEI,iBAAiB,CAACF,QAAQ,CAACH,IAAI,CAAC,CAAC;EAE5E,OAAOsB,aAAa,CAACC,IAAI,EAAElB,iBAAiB,EAAEmB,WAAW,CAAC;AAC5D,CAAC;AAED,MAAMW,QAAQ,GAAG;EACfC,SAAS,EAAEH;AACb,CAAC;AAAC,IAAAI,QAAA,GAAAC,OAAA,CAAA3E,OAAA,GAEawE,QAAQ","ignoreList":[]}
|
|
@@ -11,45 +11,45 @@ const precinct = precinctNonWired.default;
|
|
|
11
11
|
describe('node-precinct', () => {
|
|
12
12
|
describe('paperwork', () => {
|
|
13
13
|
// todo: currently it doesn't work because we set it with bit-no-check
|
|
14
|
-
it.skip('returns the dependencies for the given filepath', () => {
|
|
15
|
-
assert.ok(Object.keys(precinct.paperwork(`${fixturesFullPath}/es6.js`)).length);
|
|
16
|
-
assert.ok(Object.keys(precinct.paperwork(`${fixturesFullPath}/styles.scss`)).length);
|
|
14
|
+
it.skip('returns the dependencies for the given filepath', async () => {
|
|
15
|
+
assert.ok(Object.keys(await precinct.paperwork(`${fixturesFullPath}/es6.js`)).length);
|
|
16
|
+
assert.ok(Object.keys(await precinct.paperwork(`${fixturesFullPath}/styles.scss`)).length);
|
|
17
17
|
// todo: uncomment the next line and typescript.ts file once we have a way to ignore some component files from compiling/parsing altogether
|
|
18
|
-
// assert.ok(Object.keys(precinct.paperwork(`${fixturesFullPath}/typescript.ts`)).length);
|
|
19
|
-
assert.ok(Object.keys(precinct.paperwork(`${fixturesFullPath}/styles.css`)).length);
|
|
18
|
+
// assert.ok(Object.keys(await precinct.paperwork(`${fixturesFullPath}/typescript.ts`)).length);
|
|
19
|
+
assert.ok(Object.keys(await precinct.paperwork(`${fixturesFullPath}/styles.css`)).length);
|
|
20
20
|
});
|
|
21
|
-
it('throws if the file cannot be found', () => {
|
|
22
|
-
assert.
|
|
23
|
-
precinct.paperwork('foo');
|
|
21
|
+
it('throws if the file cannot be found', async () => {
|
|
22
|
+
await assert.rejects(async () => {
|
|
23
|
+
await precinct.paperwork('foo');
|
|
24
24
|
});
|
|
25
25
|
});
|
|
26
|
-
it('filters out core modules if options.includeCore is false', () => {
|
|
27
|
-
const deps = precinct.paperwork(`${fixturesFullPath}/coreModules.js`, {
|
|
26
|
+
it('filters out core modules if options.includeCore is false', async () => {
|
|
27
|
+
const deps = await precinct.paperwork(`${fixturesFullPath}/coreModules.js`, {
|
|
28
28
|
includeCore: false
|
|
29
29
|
});
|
|
30
30
|
assert(!deps.length);
|
|
31
31
|
});
|
|
32
32
|
|
|
33
33
|
// todo: currently it doesn't work because we set it with bit-no-check
|
|
34
|
-
it.skip('does not filter out core modules by default', () => {
|
|
35
|
-
const deps = precinct.paperwork(`${fixturesFullPath}/coreModules.js`);
|
|
34
|
+
it.skip('does not filter out core modules by default', async () => {
|
|
35
|
+
const deps = await precinct.paperwork(`${fixturesFullPath}/coreModules.js`);
|
|
36
36
|
assert(Object.keys(deps).length);
|
|
37
37
|
});
|
|
38
38
|
|
|
39
39
|
// todo: currently it doesn't work because we set it with bit-no-check
|
|
40
|
-
it.skip('supports passing detective configuration', () => {
|
|
40
|
+
it.skip('supports passing detective configuration', async () => {
|
|
41
41
|
const config = {
|
|
42
42
|
amd: {
|
|
43
43
|
skipLazyLoaded: true
|
|
44
44
|
}
|
|
45
45
|
};
|
|
46
|
-
const deps = precinct.paperwork(`${fixturesFullPath}/amd.js`, {
|
|
46
|
+
const deps = await precinct.paperwork(`${fixturesFullPath}/amd.js`, {
|
|
47
47
|
includeCore: false,
|
|
48
48
|
amd: config.amd
|
|
49
49
|
});
|
|
50
50
|
assert.deepEqual(deps, ['./a', './b']);
|
|
51
51
|
});
|
|
52
|
-
it('supports passing env detectors', () => {
|
|
52
|
+
it('supports passing env detectors', async () => {
|
|
53
53
|
const detector = {
|
|
54
54
|
detect: fileContent => {
|
|
55
55
|
return fileContent.indexOf('foo') === -1 ? [] : ['foo'];
|
|
@@ -61,21 +61,21 @@ describe('node-precinct', () => {
|
|
|
61
61
|
},
|
|
62
62
|
type: 'foo'
|
|
63
63
|
};
|
|
64
|
-
const result = precinct.paperwork(`${fixturesFullPath}/foo.foo`, {
|
|
64
|
+
const result = await precinct.paperwork(`${fixturesFullPath}/foo.foo`, {
|
|
65
65
|
envDetectors: [detector]
|
|
66
66
|
});
|
|
67
67
|
assert.deepEqual(result, []);
|
|
68
|
-
const result2 = precinct.paperwork(`${fixturesFullPath}/bar.foo`, {
|
|
68
|
+
const result2 = await precinct.paperwork(`${fixturesFullPath}/bar.foo`, {
|
|
69
69
|
envDetectors: [detector]
|
|
70
70
|
});
|
|
71
71
|
assert.deepEqual(result2, ['foo']);
|
|
72
72
|
});
|
|
73
73
|
describe('when given detective configuration', () => {
|
|
74
74
|
// This test case doesn't fit the current implementation of precinct.
|
|
75
|
-
it.skip('still does not filter out core module by default', () => {
|
|
75
|
+
it.skip('still does not filter out core module by default', async () => {
|
|
76
76
|
const stub = sinon.stub().returns([]);
|
|
77
77
|
const revert = precinctNonWired.__set__('precinct', stub);
|
|
78
|
-
precinct.paperwork(`${fixturesFullPath}/amd.js`, {
|
|
78
|
+
await precinct.paperwork(`${fixturesFullPath}/amd.js`, {
|
|
79
79
|
amd: {
|
|
80
80
|
skipLazyLoaded: true
|
|
81
81
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["assert","require","path","rewire","sinon","fixtures","fixturesFullPath","resolve","__dirname","precinctNonWired","precinct","default","describe","it","skip","ok","Object","keys","paperwork","length","
|
|
1
|
+
{"version":3,"names":["assert","require","path","rewire","sinon","fixtures","fixturesFullPath","resolve","__dirname","precinctNonWired","precinct","default","describe","it","skip","ok","Object","keys","paperwork","length","rejects","deps","includeCore","config","amd","skipLazyLoaded","deepEqual","detector","detect","fileContent","indexOf","isSupported","ext","type","result","envDetectors","result2","stub","returns","revert","__set__","equal","args"],"sources":["index.spec.ts"],"sourcesContent":["import type { DependencyDetector } from '@teambit/dependency-resolver';\n\nconst assert = require('assert');\nconst path = require('path');\nconst rewire = require('rewire');\nconst sinon = require('sinon');\n\nconst fixtures = '../fixtures/precinct';\nconst fixturesFullPath = path.resolve(__dirname, fixtures);\n\nconst precinctNonWired = rewire('./');\nconst precinct = precinctNonWired.default;\n\ndescribe('node-precinct', () => {\n describe('paperwork', () => {\n // todo: currently it doesn't work because we set it with bit-no-check\n it.skip('returns the dependencies for the given filepath', async () => {\n assert.ok(Object.keys(await precinct.paperwork(`${fixturesFullPath}/es6.js`)).length);\n assert.ok(Object.keys(await precinct.paperwork(`${fixturesFullPath}/styles.scss`)).length);\n // todo: uncomment the next line and typescript.ts file once we have a way to ignore some component files from compiling/parsing altogether\n // assert.ok(Object.keys(await precinct.paperwork(`${fixturesFullPath}/typescript.ts`)).length);\n assert.ok(Object.keys(await precinct.paperwork(`${fixturesFullPath}/styles.css`)).length);\n });\n\n it('throws if the file cannot be found', async () => {\n await assert.rejects(async () => {\n await precinct.paperwork('foo');\n });\n });\n\n it('filters out core modules if options.includeCore is false', async () => {\n const deps = await precinct.paperwork(`${fixturesFullPath}/coreModules.js`, {\n includeCore: false,\n });\n\n assert(!deps.length);\n });\n\n // todo: currently it doesn't work because we set it with bit-no-check\n it.skip('does not filter out core modules by default', async () => {\n const deps = await precinct.paperwork(`${fixturesFullPath}/coreModules.js`);\n assert(Object.keys(deps).length);\n });\n\n // todo: currently it doesn't work because we set it with bit-no-check\n it.skip('supports passing detective configuration', async () => {\n const config = {\n amd: {\n skipLazyLoaded: true,\n },\n };\n\n const deps = await precinct.paperwork(`${fixturesFullPath}/amd.js`, {\n includeCore: false,\n amd: config.amd,\n });\n assert.deepEqual(deps, ['./a', './b']);\n });\n\n it('supports passing env detectors', async () => {\n const detector: DependencyDetector = {\n detect: (fileContent: string) => {\n return fileContent.indexOf('foo') === -1 ? [] : ['foo'];\n },\n isSupported: ({ ext }) => {\n return ext === '.foo';\n },\n type: 'foo',\n };\n const result = await precinct.paperwork(`${fixturesFullPath}/foo.foo`, {\n envDetectors: [detector],\n });\n assert.deepEqual(result, []);\n\n const result2 = await precinct.paperwork(`${fixturesFullPath}/bar.foo`, {\n envDetectors: [detector],\n });\n assert.deepEqual(result2, ['foo']);\n });\n\n describe('when given detective configuration', () => {\n // This test case doesn't fit the current implementation of precinct.\n it.skip('still does not filter out core module by default', async () => {\n const stub = sinon.stub().returns([]);\n const revert = precinctNonWired.__set__('precinct', stub);\n\n await precinct.paperwork(`${fixturesFullPath}/amd.js`, {\n amd: {\n skipLazyLoaded: true,\n },\n });\n\n assert.equal(stub.args[0][1].includeCore, true);\n revert();\n });\n });\n });\n});\n"],"mappings":";;AAEA,MAAMA,MAAM,GAAGC,OAAO,CAAC,QAAQ,CAAC;AAChC,MAAMC,IAAI,GAAGD,OAAO,CAAC,MAAM,CAAC;AAC5B,MAAME,MAAM,GAAGF,OAAO,CAAC,QAAQ,CAAC;AAChC,MAAMG,KAAK,GAAGH,OAAO,CAAC,OAAO,CAAC;AAE9B,MAAMI,QAAQ,GAAG,sBAAsB;AACvC,MAAMC,gBAAgB,GAAGJ,IAAI,CAACK,OAAO,CAACC,SAAS,EAAEH,QAAQ,CAAC;AAE1D,MAAMI,gBAAgB,GAAGN,MAAM,CAAC,IAAI,CAAC;AACrC,MAAMO,QAAQ,GAAGD,gBAAgB,CAACE,OAAO;AAEzCC,QAAQ,CAAC,eAAe,EAAE,MAAM;EAC9BA,QAAQ,CAAC,WAAW,EAAE,MAAM;IAC1B;IACAC,EAAE,CAACC,IAAI,CAAC,iDAAiD,EAAE,YAAY;MACrEd,MAAM,CAACe,EAAE,CAACC,MAAM,CAACC,IAAI,CAAC,MAAMP,QAAQ,CAACQ,SAAS,CAAC,GAAGZ,gBA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,QAAQ,CAACQ,SAAS,CAAC,GAAGZ,gBAAgB,SAAS,EAAE;UACrDkB,GAAG,EAAE;YACHC,cAAc,EAAE;UAClB;QACF,CAAC,CAAC;QAEFzB,MAAM,CAACyC,KAAK,CAACJ,IAAI,CAACK,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAACpB,WAAW,EAAE,IAAI,CAAC;QAC/CiB,MAAM,CAAC,CAAC;MACV,CAAC,CAAC;IACJ,CAAC,CAAC;EACJ,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -172,7 +172,7 @@ export async function getDependencyTree({
|
|
|
172
172
|
}
|
|
173
173
|
return path.resolve(componentDir, filePath);
|
|
174
174
|
});
|
|
175
|
-
const { madgeTree, skipped, pathMap, errors } = generateTree(fullPaths, config);
|
|
175
|
+
const { madgeTree, skipped, pathMap, errors } = await generateTree(fullPaths, config);
|
|
176
176
|
const tree: DependenciesTree = MadgeTreeToDependenciesTree(madgeTree, componentDir);
|
|
177
177
|
const { missingGroups, foundPackages } = new MissingHandler(
|
|
178
178
|
skipped,
|