@teambit/dependencies 1.0.330 → 1.0.331
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/artifacts/__bit_junit.xml +203 -5
- package/artifacts/schema.json +2016 -1173
- package/dependencies-loader/apply-overrides.ts +3 -3
- package/dependencies-loader/auto-detect-deps.ts +16 -13
- package/dependencies-loader/dependencies-loader.ts +1 -1
- package/dist/dependencies-loader/apply-overrides.js +12 -5
- package/dist/dependencies-loader/apply-overrides.js.map +1 -1
- package/dist/dependencies-loader/auto-detect-deps.d.ts +4 -4
- package/dist/dependencies-loader/auto-detect-deps.js +14 -14
- package/dist/dependencies-loader/auto-detect-deps.js.map +1 -1
- package/dist/dependencies-loader/dependencies-loader.js +4 -4
- package/dist/dependencies-loader/dependencies-loader.js.map +1 -1
- package/dist/files-dependency-builder/build-tree.d.ts +11 -0
- package/dist/files-dependency-builder/build-tree.js +233 -0
- package/dist/files-dependency-builder/build-tree.js.map +1 -0
- package/dist/files-dependency-builder/build-tree.spec.d.ts +1 -0
- package/dist/files-dependency-builder/build-tree.spec.js +154 -0
- package/dist/files-dependency-builder/build-tree.spec.js.map +1 -0
- package/dist/files-dependency-builder/dependency-tree/Config.d.ts +4 -0
- package/dist/files-dependency-builder/dependency-tree/Config.js +74 -0
- package/dist/files-dependency-builder/dependency-tree/Config.js.map +1 -0
- package/dist/files-dependency-builder/dependency-tree/index.d.ts +15 -0
- package/dist/files-dependency-builder/dependency-tree/index.js +272 -0
- package/dist/files-dependency-builder/dependency-tree/index.js.map +1 -0
- package/dist/files-dependency-builder/dependency-tree/index.spec.d.ts +1 -0
- package/dist/files-dependency-builder/dependency-tree/index.spec.js +877 -0
- package/dist/files-dependency-builder/dependency-tree/index.spec.js.map +1 -0
- package/dist/files-dependency-builder/detectives/detective-css/index.d.ts +1 -0
- package/dist/files-dependency-builder/detectives/detective-css/index.js +18 -0
- package/dist/files-dependency-builder/detectives/detective-css/index.js.map +1 -0
- package/dist/files-dependency-builder/detectives/detective-es6/index.d.ts +1 -0
- package/dist/files-dependency-builder/detectives/detective-es6/index.js +18 -0
- package/dist/files-dependency-builder/detectives/detective-es6/index.js.map +1 -0
- package/dist/files-dependency-builder/detectives/detective-less/index.d.ts +1 -0
- package/dist/files-dependency-builder/detectives/detective-less/index.js +18 -0
- package/dist/files-dependency-builder/detectives/detective-less/index.js.map +1 -0
- package/dist/files-dependency-builder/detectives/detective-sass/index.d.ts +1 -0
- package/dist/files-dependency-builder/detectives/detective-sass/index.js +18 -0
- package/dist/files-dependency-builder/detectives/detective-sass/index.js.map +1 -0
- package/dist/files-dependency-builder/detectives/detective-scss/index.d.ts +1 -0
- package/dist/files-dependency-builder/detectives/detective-scss/index.js +18 -0
- package/dist/files-dependency-builder/detectives/detective-scss/index.js.map +1 -0
- package/dist/files-dependency-builder/detectives/detective-typescript/index.d.ts +1 -0
- package/dist/files-dependency-builder/detectives/detective-typescript/index.js +18 -0
- package/dist/files-dependency-builder/detectives/detective-typescript/index.js.map +1 -0
- package/dist/files-dependency-builder/detector-hook.d.ts +47 -0
- package/dist/files-dependency-builder/detector-hook.js +29 -0
- package/dist/files-dependency-builder/detector-hook.js.map +1 -0
- package/dist/files-dependency-builder/filing-cabinet/index.d.ts +17 -0
- package/dist/files-dependency-builder/filing-cabinet/index.js +140 -0
- package/dist/files-dependency-builder/filing-cabinet/index.js.map +1 -0
- package/dist/files-dependency-builder/filing-cabinet/index.spec.d.ts +1 -0
- package/dist/files-dependency-builder/filing-cabinet/index.spec.js +651 -0
- package/dist/files-dependency-builder/filing-cabinet/index.spec.js.map +1 -0
- package/dist/files-dependency-builder/fixtures/build-tree/a.d.ts +1 -0
- package/dist/files-dependency-builder/fixtures/build-tree/a.js +6 -0
- package/dist/files-dependency-builder/fixtures/build-tree/a.js.map +1 -0
- package/dist/files-dependency-builder/fixtures/build-tree/b.d.ts +1 -0
- package/dist/files-dependency-builder/fixtures/build-tree/b.js +6 -0
- package/dist/files-dependency-builder/fixtures/build-tree/b.js.map +1 -0
- package/dist/files-dependency-builder/fixtures/build-tree/not-link-file/file-a.d.ts +1 -0
- package/dist/files-dependency-builder/fixtures/build-tree/not-link-file/file-a.js +3 -0
- package/dist/files-dependency-builder/fixtures/build-tree/not-link-file/file-a.js.map +1 -0
- package/dist/files-dependency-builder/fixtures/build-tree/not-link-file/file-b.d.ts +1 -0
- package/dist/files-dependency-builder/fixtures/build-tree/not-link-file/file-b.js +3 -0
- package/dist/files-dependency-builder/fixtures/build-tree/not-link-file/file-b.js.map +1 -0
- package/dist/files-dependency-builder/fixtures/build-tree/not-link-file/file-c.d.ts +1 -0
- package/dist/files-dependency-builder/fixtures/build-tree/not-link-file/file-c.js +10 -0
- package/dist/files-dependency-builder/fixtures/build-tree/not-link-file/file-c.js.map +1 -0
- package/dist/files-dependency-builder/fixtures/build-tree/tree-shaking-cycle/foo.d.ts +1 -0
- package/dist/files-dependency-builder/fixtures/build-tree/tree-shaking-cycle/foo.js +3 -0
- package/dist/files-dependency-builder/fixtures/build-tree/tree-shaking-cycle/foo.js.map +1 -0
- package/dist/files-dependency-builder/fixtures/build-tree/tree-shaking-cycle/index.d.ts +1 -0
- package/dist/files-dependency-builder/fixtures/build-tree/tree-shaking-cycle/index.js +21 -0
- package/dist/files-dependency-builder/fixtures/build-tree/tree-shaking-cycle/index.js.map +1 -0
- package/dist/files-dependency-builder/fixtures/build-tree/tree-shaking-cycle/is-string.d.ts +2 -0
- package/dist/files-dependency-builder/fixtures/build-tree/tree-shaking-cycle/is-string.js +18 -0
- package/dist/files-dependency-builder/fixtures/build-tree/tree-shaking-cycle/is-string.js.map +1 -0
- package/dist/files-dependency-builder/fixtures/build-tree/tree-shaking-cycle/self-cycle.d.ts +2 -0
- package/dist/files-dependency-builder/fixtures/build-tree/tree-shaking-cycle/self-cycle.js +20 -0
- package/dist/files-dependency-builder/fixtures/build-tree/tree-shaking-cycle/self-cycle.js.map +1 -0
- package/dist/files-dependency-builder/fixtures/build-tree/unparsed.d.ts +0 -0
- package/dist/files-dependency-builder/fixtures/build-tree/unparsed.js +5 -0
- package/dist/files-dependency-builder/fixtures/build-tree/unparsed.js.map +1 -0
- package/dist/files-dependency-builder/fixtures/dependency-tree/amd/a.d.ts +0 -0
- package/dist/files-dependency-builder/fixtures/dependency-tree/amd/a.js +10 -0
- package/dist/files-dependency-builder/fixtures/dependency-tree/amd/a.js.map +1 -0
- package/dist/files-dependency-builder/fixtures/dependency-tree/amd/b.d.ts +0 -0
- package/dist/files-dependency-builder/fixtures/dependency-tree/amd/b.js +10 -0
- package/dist/files-dependency-builder/fixtures/dependency-tree/amd/b.js.map +1 -0
- package/dist/files-dependency-builder/fixtures/dependency-tree/amd/c.d.ts +0 -0
- package/dist/files-dependency-builder/fixtures/dependency-tree/amd/c.js +6 -0
- package/dist/files-dependency-builder/fixtures/dependency-tree/amd/c.js.map +1 -0
- package/dist/files-dependency-builder/fixtures/dependency-tree/commonjs/a.d.ts +1 -0
- package/dist/files-dependency-builder/fixtures/dependency-tree/commonjs/a.js +6 -0
- package/dist/files-dependency-builder/fixtures/dependency-tree/commonjs/a.js.map +1 -0
- package/dist/files-dependency-builder/fixtures/dependency-tree/commonjs/b.d.ts +1 -0
- package/dist/files-dependency-builder/fixtures/dependency-tree/commonjs/b.js +6 -0
- package/dist/files-dependency-builder/fixtures/dependency-tree/commonjs/b.js.map +1 -0
- package/dist/files-dependency-builder/fixtures/dependency-tree/commonjs/c.d.ts +1 -0
- package/dist/files-dependency-builder/fixtures/dependency-tree/commonjs/c.js +6 -0
- package/dist/files-dependency-builder/fixtures/dependency-tree/commonjs/c.js.map +1 -0
- package/dist/files-dependency-builder/fixtures/dependency-tree/onlyRealDeps/a.d.ts +1 -0
- package/dist/files-dependency-builder/fixtures/dependency-tree/onlyRealDeps/a.js +8 -0
- package/dist/files-dependency-builder/fixtures/dependency-tree/onlyRealDeps/a.js.map +1 -0
- package/dist/files-dependency-builder/fixtures/dependency-tree/webpack/aliased.d.ts +1 -0
- package/dist/files-dependency-builder/fixtures/dependency-tree/webpack/aliased.js +6 -0
- package/dist/files-dependency-builder/fixtures/dependency-tree/webpack/aliased.js.map +1 -0
- package/dist/files-dependency-builder/fixtures/dependency-tree/webpack/unaliased.d.ts +1 -0
- package/dist/files-dependency-builder/fixtures/dependency-tree/webpack/unaliased.js +6 -0
- package/dist/files-dependency-builder/fixtures/dependency-tree/webpack/unaliased.js.map +1 -0
- package/dist/files-dependency-builder/fixtures/filing-cabinet/ast.d.ts +221 -0
- package/dist/files-dependency-builder/fixtures/filing-cabinet/ast.js +259 -0
- package/dist/files-dependency-builder/fixtures/filing-cabinet/ast.js.map +1 -0
- package/dist/files-dependency-builder/fixtures/filing-cabinet/foo.d.ts +2 -0
- package/dist/files-dependency-builder/fixtures/filing-cabinet/foo.js +12 -0
- package/dist/files-dependency-builder/fixtures/filing-cabinet/foo.js.map +1 -0
- package/dist/files-dependency-builder/fixtures/filing-cabinet/foo.scss +1 -0
- package/dist/files-dependency-builder/fixtures/filing-cabinet/foo2.scss +0 -0
- package/dist/files-dependency-builder/fixtures/filing-cabinet/mockedJSFiles.d.ts +59 -0
- package/dist/files-dependency-builder/fixtures/filing-cabinet/mockedJSFiles.js +65 -0
- package/dist/files-dependency-builder/fixtures/filing-cabinet/mockedJSFiles.js.map +1 -0
- package/dist/files-dependency-builder/fixtures/filing-cabinet/root1/mod1.d.ts +1 -0
- package/dist/files-dependency-builder/fixtures/filing-cabinet/root1/mod1.js +5 -0
- package/dist/files-dependency-builder/fixtures/filing-cabinet/root1/mod1.js.map +1 -0
- package/dist/files-dependency-builder/fixtures/filing-cabinet/root2/mod2.d.ts +1 -0
- package/dist/files-dependency-builder/fixtures/filing-cabinet/root2/mod2.js +5 -0
- package/dist/files-dependency-builder/fixtures/filing-cabinet/root2/mod2.js.map +1 -0
- package/dist/files-dependency-builder/fixtures/filing-cabinet/webpack.config.d.ts +6 -0
- package/dist/files-dependency-builder/fixtures/filing-cabinet/webpack.config.js +12 -0
- package/dist/files-dependency-builder/fixtures/filing-cabinet/webpack.config.js.map +1 -0
- package/dist/files-dependency-builder/fixtures/missing-deps.d.ts +0 -0
- package/dist/files-dependency-builder/fixtures/missing-deps.js +5 -0
- package/dist/files-dependency-builder/fixtures/missing-deps.js.map +1 -0
- package/dist/files-dependency-builder/fixtures/precinct/Gruntfile.d.ts +2 -0
- package/dist/files-dependency-builder/fixtures/precinct/Gruntfile.js +24 -0
- package/dist/files-dependency-builder/fixtures/precinct/Gruntfile.js.map +1 -0
- package/dist/files-dependency-builder/fixtures/precinct/amd.d.ts +0 -0
- package/dist/files-dependency-builder/fixtures/precinct/amd.js +6 -0
- package/dist/files-dependency-builder/fixtures/precinct/amd.js.map +1 -0
- package/dist/files-dependency-builder/fixtures/precinct/bar.foo +1 -0
- package/dist/files-dependency-builder/fixtures/precinct/cjsExportLazy.d.ts +6 -0
- package/dist/files-dependency-builder/fixtures/precinct/cjsExportLazy.js +11 -0
- package/dist/files-dependency-builder/fixtures/precinct/cjsExportLazy.js.map +1 -0
- package/dist/files-dependency-builder/fixtures/precinct/commonjs.d.ts +1 -0
- package/dist/files-dependency-builder/fixtures/precinct/commonjs.js +7 -0
- package/dist/files-dependency-builder/fixtures/precinct/commonjs.js.map +1 -0
- package/dist/files-dependency-builder/fixtures/precinct/coreModules.d.ts +1 -0
- package/dist/files-dependency-builder/fixtures/precinct/coreModules.js +9 -0
- package/dist/files-dependency-builder/fixtures/precinct/coreModules.js.map +1 -0
- package/dist/files-dependency-builder/fixtures/precinct/es6.d.ts +1 -0
- package/dist/files-dependency-builder/fixtures/precinct/es6.js +15 -0
- package/dist/files-dependency-builder/fixtures/precinct/es6.js.map +1 -0
- package/dist/files-dependency-builder/fixtures/precinct/es6MixedExportLazy.d.ts +5 -0
- package/dist/files-dependency-builder/fixtures/precinct/es6MixedExportLazy.js +15 -0
- package/dist/files-dependency-builder/fixtures/precinct/es6MixedExportLazy.js.map +1 -0
- package/dist/files-dependency-builder/fixtures/precinct/es7.d.ts +1 -0
- package/dist/files-dependency-builder/fixtures/precinct/es7.js +7 -0
- package/dist/files-dependency-builder/fixtures/precinct/es7.js.map +1 -0
- package/dist/files-dependency-builder/fixtures/precinct/exampleAST.d.ts +24 -0
- package/dist/files-dependency-builder/fixtures/precinct/exampleAST.js +30 -0
- package/dist/files-dependency-builder/fixtures/precinct/exampleAST.js.map +1 -0
- package/dist/files-dependency-builder/fixtures/precinct/foo.foo +1 -0
- package/dist/files-dependency-builder/fixtures/precinct/styles.css +6 -0
- package/dist/files-dependency-builder/fixtures/precinct/styles.less +4 -0
- package/dist/files-dependency-builder/fixtures/precinct/styles.sass +2 -0
- package/dist/files-dependency-builder/fixtures/precinct/styles.scss +3 -0
- package/dist/files-dependency-builder/fixtures/precinct/styles.styl +5 -0
- package/dist/files-dependency-builder/fixtures/precinct/typescript.d.ts +0 -0
- package/dist/files-dependency-builder/fixtures/precinct/typescript.js +11 -0
- package/dist/files-dependency-builder/fixtures/precinct/typescript.js.map +1 -0
- package/dist/files-dependency-builder/fixtures/precinct/unparseable.d.ts +0 -0
- package/dist/files-dependency-builder/fixtures/precinct/unparseable.js +9 -0
- package/dist/files-dependency-builder/fixtures/precinct/unparseable.js.map +1 -0
- package/dist/files-dependency-builder/fixtures/unsupported-file.pdf +0 -0
- package/dist/files-dependency-builder/generate-tree-madge.d.ts +31 -0
- package/dist/files-dependency-builder/generate-tree-madge.js +196 -0
- package/dist/files-dependency-builder/generate-tree-madge.js.map +1 -0
- package/dist/files-dependency-builder/index.d.ts +3 -0
- package/dist/files-dependency-builder/index.js +34 -0
- package/dist/files-dependency-builder/index.js.map +1 -0
- package/dist/files-dependency-builder/missing-handler.d.ts +34 -0
- package/dist/files-dependency-builder/missing-handler.js +107 -0
- package/dist/files-dependency-builder/missing-handler.js.map +1 -0
- package/dist/files-dependency-builder/path-map.d.ts +20 -0
- package/dist/files-dependency-builder/path-map.js +46 -0
- package/dist/files-dependency-builder/path-map.js.map +1 -0
- package/dist/files-dependency-builder/precinct/index.d.ts +22 -0
- package/dist/files-dependency-builder/precinct/index.js +306 -0
- package/dist/files-dependency-builder/precinct/index.js.map +1 -0
- package/dist/files-dependency-builder/precinct/index.spec.d.ts +1 -0
- package/dist/files-dependency-builder/precinct/index.spec.js +300 -0
- package/dist/files-dependency-builder/precinct/index.spec.js.map +1 -0
- package/dist/files-dependency-builder/types/dependency-tree-type.d.ts +35 -0
- package/dist/files-dependency-builder/types/dependency-tree-type.js +34 -0
- package/dist/files-dependency-builder/types/dependency-tree-type.js.map +1 -0
- package/dist/files-dependency-builder/types/index.d.ts +0 -0
- package/dist/files-dependency-builder/types/index.js +7 -0
- package/dist/files-dependency-builder/types/index.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -1
- package/dist/resolve-pkg-data.d.ts +23 -0
- package/dist/resolve-pkg-data.js +157 -0
- package/dist/resolve-pkg-data.js.map +1 -0
- package/files-dependency-builder/build-tree.spec.ts +130 -0
- package/files-dependency-builder/build-tree.ts +185 -0
- package/files-dependency-builder/dependency-tree/Config.ts +68 -0
- package/files-dependency-builder/dependency-tree/index.spec.ts +893 -0
- package/files-dependency-builder/dependency-tree/index.ts +244 -0
- package/files-dependency-builder/detectives/detective-css/index.ts +1 -0
- package/files-dependency-builder/detectives/detective-es6/index.ts +1 -0
- package/files-dependency-builder/detectives/detective-less/index.ts +1 -0
- package/files-dependency-builder/detectives/detective-sass/index.ts +1 -0
- package/files-dependency-builder/detectives/detective-scss/index.ts +1 -0
- package/files-dependency-builder/detectives/detective-typescript/index.ts +1 -0
- package/files-dependency-builder/detector-hook.ts +69 -0
- package/files-dependency-builder/filing-cabinet/index.spec.ts +718 -0
- package/files-dependency-builder/filing-cabinet/index.ts +119 -0
- package/files-dependency-builder/fixtures/build-tree/a.js +2 -0
- package/files-dependency-builder/fixtures/build-tree/b.js +2 -0
- package/files-dependency-builder/fixtures/build-tree/not-link-file/file-a.js +2 -0
- package/files-dependency-builder/fixtures/build-tree/not-link-file/file-b.js +4 -0
- package/files-dependency-builder/fixtures/build-tree/not-link-file/file-c.js +3 -0
- package/files-dependency-builder/fixtures/build-tree/tree-shaking-cycle/foo.js +2 -0
- package/files-dependency-builder/fixtures/build-tree/tree-shaking-cycle/index.js +2 -0
- package/files-dependency-builder/fixtures/build-tree/tree-shaking-cycle/is-string.js +3 -0
- package/files-dependency-builder/fixtures/build-tree/tree-shaking-cycle/self-cycle.js +3 -0
- package/files-dependency-builder/fixtures/build-tree/unparsed.js +2 -0
- package/files-dependency-builder/fixtures/dependency-tree/amd/a.js +6 -0
- package/files-dependency-builder/fixtures/dependency-tree/amd/b.js +6 -0
- package/files-dependency-builder/fixtures/dependency-tree/amd/c.js +2 -0
- package/files-dependency-builder/fixtures/dependency-tree/commonjs/a.js +2 -0
- package/files-dependency-builder/fixtures/dependency-tree/commonjs/b.js +3 -0
- package/files-dependency-builder/fixtures/dependency-tree/commonjs/c.js +3 -0
- package/files-dependency-builder/fixtures/dependency-tree/onlyRealDeps/a.js +4 -0
- package/files-dependency-builder/fixtures/dependency-tree/webpack/aliased.js +2 -0
- package/files-dependency-builder/fixtures/dependency-tree/webpack/unaliased.js +2 -0
- package/files-dependency-builder/fixtures/filing-cabinet/ast.js +266 -0
- package/files-dependency-builder/fixtures/filing-cabinet/foo.jsx +3 -0
- package/files-dependency-builder/fixtures/filing-cabinet/foo.scss +1 -0
- package/files-dependency-builder/fixtures/filing-cabinet/foo2.scss +0 -0
- package/files-dependency-builder/fixtures/filing-cabinet/mockedJSFiles.js +61 -0
- package/files-dependency-builder/fixtures/filing-cabinet/root1/mod1.js +1 -0
- package/files-dependency-builder/fixtures/filing-cabinet/root2/mod2.js +1 -0
- package/files-dependency-builder/fixtures/filing-cabinet/webpack.config.js +8 -0
- package/files-dependency-builder/fixtures/missing-deps.js +2 -0
- package/files-dependency-builder/fixtures/precinct/Gruntfile.js +22 -0
- package/files-dependency-builder/fixtures/precinct/amd.js +2 -0
- package/files-dependency-builder/fixtures/precinct/bar.foo +1 -0
- package/files-dependency-builder/fixtures/precinct/cjsExportLazy.js +7 -0
- package/files-dependency-builder/fixtures/precinct/commonjs.js +3 -0
- package/files-dependency-builder/fixtures/precinct/coreModules.js +5 -0
- package/files-dependency-builder/fixtures/precinct/es6.js +4 -0
- package/files-dependency-builder/fixtures/precinct/es6MixedExportLazy.js +7 -0
- package/files-dependency-builder/fixtures/precinct/es7.js +3 -0
- package/files-dependency-builder/fixtures/precinct/exampleAST.js +32 -0
- package/files-dependency-builder/fixtures/precinct/foo.foo +1 -0
- package/files-dependency-builder/fixtures/precinct/styles.css +6 -0
- package/files-dependency-builder/fixtures/precinct/styles.less +4 -0
- package/files-dependency-builder/fixtures/precinct/styles.sass +2 -0
- package/files-dependency-builder/fixtures/precinct/styles.scss +3 -0
- package/files-dependency-builder/fixtures/precinct/styles.styl +5 -0
- package/files-dependency-builder/fixtures/precinct/typescript.ts +8 -0
- package/files-dependency-builder/fixtures/precinct/unparseable.js +6 -0
- package/files-dependency-builder/fixtures/unsupported-file.pdf +0 -0
- package/files-dependency-builder/generate-tree-madge.ts +200 -0
- package/files-dependency-builder/index.ts +5 -0
- package/files-dependency-builder/missing-handler.ts +76 -0
- package/files-dependency-builder/path-map.ts +38 -0
- package/files-dependency-builder/precinct/index.spec.ts +342 -0
- package/files-dependency-builder/precinct/index.ts +250 -0
- package/files-dependency-builder/types/dependency-tree-type.ts +46 -0
- package/files-dependency-builder/types/index.ts +3 -0
- package/package.json +37 -13
- /package/dist/{preview-1720513025675.js → preview-1720667996237.js} +0 -0
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
import { expect } from 'chai';
|
|
2
|
+
import { DependencyDetector } from '../detector-hook';
|
|
3
|
+
|
|
4
|
+
const assert = require('assert');
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
const rewire = require('rewire');
|
|
8
|
+
const sinon = require('sinon');
|
|
9
|
+
|
|
10
|
+
const fixtures = '../fixtures/precinct';
|
|
11
|
+
const fixturesFullPath = path.resolve(__dirname, fixtures);
|
|
12
|
+
const exampleASTPath = path.join(fixtures, 'exampleAST');
|
|
13
|
+
// eslint-disable-next-line import/no-dynamic-require, global-require
|
|
14
|
+
const ast = require(exampleASTPath);
|
|
15
|
+
|
|
16
|
+
const precinctNonWired = rewire('./');
|
|
17
|
+
const precinct = precinctNonWired.default;
|
|
18
|
+
|
|
19
|
+
function read(filename) {
|
|
20
|
+
return fs.readFileSync(path.join(fixturesFullPath, filename), 'utf8');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
describe('node-precinct', () => {
|
|
24
|
+
it('accepts an AST', () => {
|
|
25
|
+
const deps = precinct(ast);
|
|
26
|
+
const depsKeys = Object.keys(deps);
|
|
27
|
+
assert(depsKeys.length === 1);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('dangles off a given ast', () => {
|
|
31
|
+
precinct(ast);
|
|
32
|
+
assert.deepEqual(precinct.ast, ast);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('dangles off the parsed ast from a .js file', () => {
|
|
36
|
+
precinct(read('amd.js'));
|
|
37
|
+
assert.ok(precinct.ast);
|
|
38
|
+
assert.notDeepEqual(precinct.ast, ast);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('dangles off the parsed ast from a scss detective', () => {
|
|
42
|
+
precinct(read('styles.scss'), 'scss');
|
|
43
|
+
assert.notDeepEqual(precinct.ast, {});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('dangles off the parsed ast from a sass detective', () => {
|
|
47
|
+
precinct(read('styles.sass'), 'sass');
|
|
48
|
+
assert.notDeepEqual(precinct.ast, {});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('grabs dependencies of amd modules', () => {
|
|
52
|
+
const amd = precinct(read('amd.js'));
|
|
53
|
+
assert(amd.indexOf('./a') !== -1);
|
|
54
|
+
assert(amd.indexOf('./b') !== -1);
|
|
55
|
+
assert(amd.length === 2);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('grabs dependencies of commonjs modules', () => {
|
|
59
|
+
const cjs = precinct(read('commonjs.js'));
|
|
60
|
+
expect(cjs).to.have.property('./a');
|
|
61
|
+
expect(cjs).to.have.property('./b');
|
|
62
|
+
assert(Object.keys(cjs).length === 2);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('grabs dependencies of es6 modules', () => {
|
|
66
|
+
const cjs = precinct(`import { square, diag } from 'lib';
|
|
67
|
+
console.log(square(11)); // 121
|
|
68
|
+
console.log(diag(4, 3)); // 5`);
|
|
69
|
+
expect(cjs).to.have.property('lib');
|
|
70
|
+
assert(Object.keys(cjs).length === 1);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('grabs dependencies of es6 modules with embedded jsx', () => {
|
|
74
|
+
const cjs = precinct(`import { square, diag } from 'lib';
|
|
75
|
+
const tmpl = <jsx />;`);
|
|
76
|
+
expect(cjs).to.have.property('lib');
|
|
77
|
+
assert(Object.keys(cjs).length === 1);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('grabs dependencies of es6 modules with embedded es7', () => {
|
|
81
|
+
const cjs = precinct(`import { square, diag } from 'lib';
|
|
82
|
+
async function foo() {}`);
|
|
83
|
+
expect(cjs).to.have.property('lib');
|
|
84
|
+
assert(Object.keys(cjs).length === 1);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('throws errors of es6 modules with syntax errors', () => {
|
|
88
|
+
const precinctFunc = () =>
|
|
89
|
+
precinct(`import { square, diag } from 'lib' // error, semicolon
|
|
90
|
+
console.log(square(11)); // 121
|
|
91
|
+
console.log(diag(4, 3); // 5, error, missing paren`);
|
|
92
|
+
expect(precinctFunc).to.throw();
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// this is for supporting PostCSS dialect. The implementation is not merged to this project.
|
|
96
|
+
// see the following PR of node-precinct: https://github.com/dependents/node-precinct/pull/40
|
|
97
|
+
it.skip('grabs dependencies of css files', () => {
|
|
98
|
+
const css = precinct(read('styles.css'), 'css');
|
|
99
|
+
expect(css).to.have.property('foo.css');
|
|
100
|
+
expect(css).to.have.property('baz.css');
|
|
101
|
+
expect(css).to.have.property('bla.css');
|
|
102
|
+
expect(css).to.have.property('another.css');
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('grabs dependencies of scss files', function () {
|
|
106
|
+
const scss = precinct(read('styles.scss'), 'scss');
|
|
107
|
+
assert.deepEqual(scss, ['_foo', 'baz.scss']);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('grabs dependencies of sass files', () => {
|
|
111
|
+
const sass = precinct(read('styles.sass'), 'sass');
|
|
112
|
+
assert.deepEqual(sass, ['_foo']);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('grabs dependencies of stylus files', () => {
|
|
116
|
+
const result = precinct(read('styles.styl'), 'stylus');
|
|
117
|
+
const expected = ['mystyles', 'styles2.styl', 'styles3.styl', 'styles4'];
|
|
118
|
+
|
|
119
|
+
assert.deepEqual(result, expected);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('grabs dependencies of less files', () => {
|
|
123
|
+
const result = precinct(read('styles.less'), 'less');
|
|
124
|
+
const expected = ['_foo', '_bar.css', 'baz.less'];
|
|
125
|
+
|
|
126
|
+
assert.deepEqual(result, expected);
|
|
127
|
+
});
|
|
128
|
+
// todo: fix this one once we have a way to ignore some component files from compiling/parsing altogether
|
|
129
|
+
// uncomment typescript.ts
|
|
130
|
+
it.skip('grabs dependencies of typescript files', () => {
|
|
131
|
+
const result = precinct(read('typescript.ts'), 'ts');
|
|
132
|
+
const expected = ['fs', 'lib', './bar', './my-module.js', './ZipCodeValidator'];
|
|
133
|
+
|
|
134
|
+
assert.deepEqual(Object.keys(result), expected);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('throws errors of typescript modules with syntax errors', () => {
|
|
138
|
+
const precinctFunc = () =>
|
|
139
|
+
precinct(`import { square, diag } from 'lib';
|
|
140
|
+
console.log(diag(4, 3); // error, missing bracket
|
|
141
|
+
`);
|
|
142
|
+
expect(precinctFunc).to.throw();
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('supports the object form of type configuration', () => {
|
|
146
|
+
const result = precinct(read('styles.styl'), { type: 'stylus' });
|
|
147
|
+
const expected = ['mystyles', 'styles2.styl', 'styles3.styl', 'styles4'];
|
|
148
|
+
|
|
149
|
+
assert.deepEqual(result, expected);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it('yields no dependencies for es6 modules with no imports', () => {
|
|
153
|
+
const cjs = precinct(`export const sqrt = Math.sqrt;
|
|
154
|
+
export function square(x) {
|
|
155
|
+
return x * x;
|
|
156
|
+
}
|
|
157
|
+
export function diag(x, y) {
|
|
158
|
+
return sqrt(square(x) + square(y));
|
|
159
|
+
}
|
|
160
|
+
`);
|
|
161
|
+
assert.equal(Object.keys(cjs).length, 0);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it('yields no dependencies for non-modules', () => {
|
|
165
|
+
const none = precinct(`var a = new window.Foo();`);
|
|
166
|
+
assert.equal(Object.keys(none).length, 0);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it('throw on unparsable .js files', () => {
|
|
170
|
+
assert.throws(() => {
|
|
171
|
+
precinct(`{
|
|
172
|
+
"very invalid": "javascript",
|
|
173
|
+
"this", "is actually json",
|
|
174
|
+
"But" not even valid json.
|
|
175
|
+
}
|
|
176
|
+
`);
|
|
177
|
+
}, SyntaxError);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it('does not blow up when parsing a gruntfile #2', () => {
|
|
181
|
+
assert.doesNotThrow(() => {
|
|
182
|
+
precinct(read('Gruntfile.js'));
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
describe('paperwork', () => {
|
|
187
|
+
// todo: currently it doesn't work because we set it with bit-no-check
|
|
188
|
+
it.skip('returns the dependencies for the given filepath', () => {
|
|
189
|
+
assert.ok(Object.keys(precinct.paperwork(`${fixturesFullPath}/es6.js`)).length);
|
|
190
|
+
assert.ok(Object.keys(precinct.paperwork(`${fixturesFullPath}/styles.scss`)).length);
|
|
191
|
+
// todo: uncomment the next line and typescript.ts file once we have a way to ignore some component files from compiling/parsing altogether
|
|
192
|
+
// assert.ok(Object.keys(precinct.paperwork(`${fixturesFullPath}/typescript.ts`)).length);
|
|
193
|
+
assert.ok(Object.keys(precinct.paperwork(`${fixturesFullPath}/styles.css`)).length);
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it('throws if the file cannot be found', () => {
|
|
197
|
+
assert.throws(() => {
|
|
198
|
+
precinct.paperwork('foo');
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it('filters out core modules if options.includeCore is false', () => {
|
|
203
|
+
const deps = precinct.paperwork(`${fixturesFullPath}/coreModules.js`, {
|
|
204
|
+
includeCore: false,
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
assert(!deps.length);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
// todo: currently it doesn't work because we set it with bit-no-check
|
|
211
|
+
it.skip('does not filter out core modules by default', () => {
|
|
212
|
+
const deps = precinct.paperwork(`${fixturesFullPath}/coreModules.js`);
|
|
213
|
+
assert(Object.keys(deps).length);
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
// todo: currently it doesn't work because we set it with bit-no-check
|
|
217
|
+
it.skip('supports passing detective configuration', () => {
|
|
218
|
+
const config = {
|
|
219
|
+
amd: {
|
|
220
|
+
skipLazyLoaded: true,
|
|
221
|
+
},
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
const deps = precinct.paperwork(`${fixturesFullPath}/amd.js`, {
|
|
225
|
+
includeCore: false,
|
|
226
|
+
amd: config.amd,
|
|
227
|
+
});
|
|
228
|
+
assert.deepEqual(deps, ['./a', './b']);
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
it('supports passing env detectors', () => {
|
|
232
|
+
const detector: DependencyDetector = {
|
|
233
|
+
detect: (fileContent: string) => {
|
|
234
|
+
return fileContent.indexOf('foo') === -1 ? [] : ['foo'];
|
|
235
|
+
},
|
|
236
|
+
isSupported: ({ ext }) => {
|
|
237
|
+
return ext === '.foo';
|
|
238
|
+
},
|
|
239
|
+
type: 'foo',
|
|
240
|
+
};
|
|
241
|
+
const result = precinct.paperwork(`${fixturesFullPath}/foo.foo`, {
|
|
242
|
+
envDetectors: [detector],
|
|
243
|
+
});
|
|
244
|
+
assert.deepEqual(result, []);
|
|
245
|
+
|
|
246
|
+
const result2 = precinct.paperwork(`${fixturesFullPath}/bar.foo`, {
|
|
247
|
+
envDetectors: [detector],
|
|
248
|
+
});
|
|
249
|
+
assert.deepEqual(result2, ['foo']);
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
describe('when given detective configuration', () => {
|
|
253
|
+
// This test case doesn't fit the current implementation of precinct.
|
|
254
|
+
it.skip('still does not filter out core module by default', () => {
|
|
255
|
+
const stub = sinon.stub().returns([]);
|
|
256
|
+
const revert = precinctNonWired.__set__('precinct', stub);
|
|
257
|
+
|
|
258
|
+
precinct.paperwork(`${fixturesFullPath}/amd.js`, {
|
|
259
|
+
amd: {
|
|
260
|
+
skipLazyLoaded: true,
|
|
261
|
+
},
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
assert.equal(stub.args[0][1].includeCore, true);
|
|
265
|
+
revert();
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
describe('when given a configuration object', () => {
|
|
271
|
+
it('passes amd config to the amd detective', () => {
|
|
272
|
+
const config = {
|
|
273
|
+
amd: {
|
|
274
|
+
skipLazyLoaded: true,
|
|
275
|
+
},
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
const deps = precinct(read('amd.js'), config);
|
|
279
|
+
assert.deepEqual(deps, ['./a', './b']);
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
describe('that sets mixedImports for es6', () => {
|
|
283
|
+
describe('for a file identified as es6', () => {
|
|
284
|
+
it('returns both the commonjs and es6 dependencies', () => {
|
|
285
|
+
const deps = precinct(
|
|
286
|
+
`import foo from './foo';
|
|
287
|
+
var bar = require('./bar');`,
|
|
288
|
+
{
|
|
289
|
+
es6: {
|
|
290
|
+
mixedImports: true,
|
|
291
|
+
},
|
|
292
|
+
}
|
|
293
|
+
);
|
|
294
|
+
|
|
295
|
+
assert.equal(Object.keys(deps).length, 2);
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
describe('for a file identified as cjs', () => {
|
|
300
|
+
it('returns both the commonjs and es6 dependencies', () => {
|
|
301
|
+
const deps = precinct(
|
|
302
|
+
`var bar = require('./bar');
|
|
303
|
+
import foo from './foo';`,
|
|
304
|
+
{
|
|
305
|
+
es6: {
|
|
306
|
+
mixedImports: true,
|
|
307
|
+
},
|
|
308
|
+
}
|
|
309
|
+
);
|
|
310
|
+
|
|
311
|
+
assert.equal(Object.keys(deps).length, 2);
|
|
312
|
+
});
|
|
313
|
+
});
|
|
314
|
+
});
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
describe('when lazy exported dependencies in CJS', () => {
|
|
318
|
+
it('grabs those lazy dependencies', () => {
|
|
319
|
+
const cjs = precinct(read('cjsExportLazy.js'));
|
|
320
|
+
expect(cjs).to.have.property('./amd');
|
|
321
|
+
expect(cjs).to.have.property('./es6');
|
|
322
|
+
expect(cjs).to.have.property('./es7');
|
|
323
|
+
assert.equal(Object.keys(cjs).length, 3);
|
|
324
|
+
});
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
describe('when given an es6 file', () => {
|
|
328
|
+
describe('that uses CJS imports for lazy dependencies', () => {
|
|
329
|
+
it('grabs the lazy imports', () => {
|
|
330
|
+
const es6 = precinct(read('es6MixedExportLazy.js'), {
|
|
331
|
+
es6: {
|
|
332
|
+
mixedImports: true,
|
|
333
|
+
},
|
|
334
|
+
});
|
|
335
|
+
expect(es6).to.have.property('./amd');
|
|
336
|
+
expect(es6).to.have.property('./es6');
|
|
337
|
+
expect(es6).to.have.property('./es7');
|
|
338
|
+
assert.equal(Object.keys(es6).length, 3);
|
|
339
|
+
});
|
|
340
|
+
});
|
|
341
|
+
});
|
|
342
|
+
});
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* this file had been forked from https://github.com/dependents/node-precinct
|
|
3
|
+
*/
|
|
4
|
+
import fs from 'fs-extra';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
|
|
7
|
+
// @ts-ignore we currently have @types/node as v12, and this is available > 16. once updated, remove the ts-ignore
|
|
8
|
+
import { isBuiltin } from 'module';
|
|
9
|
+
|
|
10
|
+
import getModuleType from 'module-definition';
|
|
11
|
+
import Walker from 'node-source-walk';
|
|
12
|
+
|
|
13
|
+
import detectiveAmd from 'detective-amd';
|
|
14
|
+
import detectiveStylus from 'detective-stylus';
|
|
15
|
+
|
|
16
|
+
import detectiveEs6 from '@teambit/node.deps-detectors.detective-es6';
|
|
17
|
+
import detectiveCss from '@teambit/styling.deps-detectors.detective-css';
|
|
18
|
+
import detectiveLess from '@teambit/styling.deps-detectors.detective-less';
|
|
19
|
+
import detectiveSass from '@teambit/styling.deps-detectors.detective-sass';
|
|
20
|
+
import detectiveScss from '@teambit/styling.deps-detectors.detective-scss';
|
|
21
|
+
import detectiveTypeScript from '@teambit/typescript.deps-detectors.detective-typescript';
|
|
22
|
+
|
|
23
|
+
import { DependencyDetector, DetectorHook } from '../detector-hook';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The file info object.
|
|
27
|
+
* - `ext` is the file extension.
|
|
28
|
+
* - `content` is the input file content.
|
|
29
|
+
* - `type` is the parsed file type from ext or content.
|
|
30
|
+
* - `ast` is the eventually consumed content by the corresponding detective.
|
|
31
|
+
*/
|
|
32
|
+
type FileInfo = {
|
|
33
|
+
ext: string;
|
|
34
|
+
content: string | object;
|
|
35
|
+
type: string;
|
|
36
|
+
ast: any;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
type Options = {
|
|
40
|
+
envDetectors?: DependencyDetector[];
|
|
41
|
+
useContent?: boolean;
|
|
42
|
+
includeCore?: boolean;
|
|
43
|
+
type?: string;
|
|
44
|
+
[lang: string]: any;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
type BuiltinDeps = string[] | Record<string, any>;
|
|
48
|
+
type Detective = (fileContent: string | object, options?: any) => BuiltinDeps;
|
|
49
|
+
|
|
50
|
+
const jsExt = ['.js', '.jsx', '.cjs', '.mjs'];
|
|
51
|
+
|
|
52
|
+
const extToType = {
|
|
53
|
+
'.css': 'css',
|
|
54
|
+
'.sass': 'sass',
|
|
55
|
+
'.less': 'less',
|
|
56
|
+
'.scss': 'scss',
|
|
57
|
+
'.styl': 'stylus',
|
|
58
|
+
'.mts': 'ts',
|
|
59
|
+
'.cts': 'ts',
|
|
60
|
+
'.ts': 'ts',
|
|
61
|
+
'.tsx': 'ts',
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const typeToDetective: Record<string, Detective> = {
|
|
65
|
+
css: detectiveCss,
|
|
66
|
+
sass: detectiveSass,
|
|
67
|
+
less: detectiveLess,
|
|
68
|
+
scss: detectiveScss,
|
|
69
|
+
stylus: detectiveStylus,
|
|
70
|
+
ts: detectiveTypeScript,
|
|
71
|
+
commonjs: detectiveEs6,
|
|
72
|
+
es6: detectiveEs6,
|
|
73
|
+
amd: detectiveAmd,
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const debug = require('debug')('precinct');
|
|
77
|
+
|
|
78
|
+
const detectorHook = new DetectorHook();
|
|
79
|
+
|
|
80
|
+
const assign = (o1, o2) => {
|
|
81
|
+
// eslint-disable-next-line
|
|
82
|
+
for (const key in o2) {
|
|
83
|
+
// eslint-disable-next-line
|
|
84
|
+
if (o2.hasOwnProperty(key)) {
|
|
85
|
+
o1[key] = o2[key];
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return o1;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Get file info from the given file path.
|
|
94
|
+
*/
|
|
95
|
+
const getFileInfo = (filename: string): FileInfo => {
|
|
96
|
+
const ext = path.extname(filename);
|
|
97
|
+
const content = fs.readFileSync(filename, 'utf8');
|
|
98
|
+
return {
|
|
99
|
+
ext,
|
|
100
|
+
content,
|
|
101
|
+
// determined later
|
|
102
|
+
type: '',
|
|
103
|
+
// initialized with the content
|
|
104
|
+
ast: content,
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Get the non-JS detective for the given file info.
|
|
110
|
+
* The type of the file would be determined as well.
|
|
111
|
+
* Return undefined if no proper detective found, perhaps it's plain
|
|
112
|
+
* JavaScript or unknown content. We can deal with it later.
|
|
113
|
+
*/
|
|
114
|
+
const getDetector = (fileInfo: FileInfo, options?: Options): Detective | undefined => {
|
|
115
|
+
const { ext } = fileInfo;
|
|
116
|
+
const normalizedOptions: Options = options || {};
|
|
117
|
+
|
|
118
|
+
// from env detectors
|
|
119
|
+
if (options?.envDetectors) {
|
|
120
|
+
for (const detector of options.envDetectors) {
|
|
121
|
+
if (detector.isSupported({ ext })) {
|
|
122
|
+
fileInfo.type = detector.type || '';
|
|
123
|
+
return detector.detect as Detective;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// from builtin detectors
|
|
129
|
+
// - check `fileInfo.type` first to support `precinct(content, { type })`
|
|
130
|
+
const type = fileInfo.type || extToType[ext];
|
|
131
|
+
if (typeToDetective[type]) {
|
|
132
|
+
const detective = typeToDetective[type];
|
|
133
|
+
fileInfo.type = type;
|
|
134
|
+
// special logic for tsx files
|
|
135
|
+
if (ext === '.tsx') {
|
|
136
|
+
if (!normalizedOptions.ts) normalizedOptions.ts = {};
|
|
137
|
+
normalizedOptions.ts.jsx = true;
|
|
138
|
+
}
|
|
139
|
+
return detective;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// from global detector hook (legacy)
|
|
143
|
+
if (detectorHook.isSupported(ext)) {
|
|
144
|
+
const detector = detectorHook.getDetector(ext);
|
|
145
|
+
if (detector) {
|
|
146
|
+
fileInfo.type = ext;
|
|
147
|
+
typeToDetective[ext] = detector.detect as Detective;
|
|
148
|
+
return detector.detect as Detective;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return undefined;
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Get the JS detective (amd/es6/cjs) for the given file info.
|
|
157
|
+
* The type and ast of the file would be determined as well.
|
|
158
|
+
*/
|
|
159
|
+
const getJsDetector = (fileInfo: FileInfo, options?: Options): Detective | undefined => {
|
|
160
|
+
if (!jsExt.includes(fileInfo.ext)) {
|
|
161
|
+
return undefined;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (typeof fileInfo.content !== 'object') {
|
|
165
|
+
const walker = new Walker();
|
|
166
|
+
try {
|
|
167
|
+
fileInfo.ast = walker.parse(fileInfo.content);
|
|
168
|
+
} catch (e: any) {
|
|
169
|
+
debug('could not parse content: %s', e.message);
|
|
170
|
+
throw e;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const useContent = options?.useContent;
|
|
175
|
+
const type = useContent ? getModuleType.fromSource(fileInfo.content) : getModuleType.fromSource(fileInfo.ast);
|
|
176
|
+
const detector = typeToDetective[type];
|
|
177
|
+
fileInfo.type = type;
|
|
178
|
+
|
|
179
|
+
return detector;
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Normalize the deps into an array.
|
|
184
|
+
*/
|
|
185
|
+
const normalizeDeps = (deps: BuiltinDeps, includeCore?: boolean): string[] => {
|
|
186
|
+
const normalizedDeps = Array.isArray(deps) ? deps : Object.keys(deps);
|
|
187
|
+
return includeCore ? normalizedDeps : normalizedDeps.filter((d) => !isBuiltin(d));
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
const getDepsFromFile = (filename: string, options?: Options): string[] => {
|
|
191
|
+
const normalizedOptions: Options = assign({ includeCore: true }, options || {});
|
|
192
|
+
const fileInfo = getFileInfo(filename);
|
|
193
|
+
if (
|
|
194
|
+
typeof fileInfo.content === 'string' &&
|
|
195
|
+
(fileInfo.content.startsWith('// @bit-no-check') || fileInfo.content.startsWith('/* @bit-no-check'))
|
|
196
|
+
) {
|
|
197
|
+
debug(`skipping file ${filename}, it has a @bit-no-check comment`);
|
|
198
|
+
return [];
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const detective = getDetector(fileInfo, normalizedOptions) || getJsDetector(fileInfo, normalizedOptions);
|
|
202
|
+
if (!detective) {
|
|
203
|
+
debug(`skipping unsupported file ${filename}`);
|
|
204
|
+
return [];
|
|
205
|
+
}
|
|
206
|
+
debug('module type: ', fileInfo.type);
|
|
207
|
+
|
|
208
|
+
const deps = detective(fileInfo.ast, normalizedOptions[fileInfo.type]);
|
|
209
|
+
|
|
210
|
+
return normalizeDeps(deps, normalizedOptions?.includeCore);
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Finds the list of dependencies for the given file
|
|
215
|
+
*
|
|
216
|
+
* @param {String|Object} content - File's content or AST
|
|
217
|
+
* @param {Object} [options]
|
|
218
|
+
* @param {String} [options.type] - The type of content being passed in. Useful if you want to use a non-js detective
|
|
219
|
+
* @return {String[]}
|
|
220
|
+
*/
|
|
221
|
+
// eslint-disable-next-line complexity
|
|
222
|
+
const precinct = (content: string | object, options?: string | Options): BuiltinDeps => {
|
|
223
|
+
// Legacy form backCompat where type was the second parameter
|
|
224
|
+
const normalizedOptions: Options = typeof options === 'string' ? { type: options } : options || {};
|
|
225
|
+
const type = normalizedOptions.type || '';
|
|
226
|
+
|
|
227
|
+
debug('options given: ', normalizedOptions);
|
|
228
|
+
|
|
229
|
+
const fileInfo: FileInfo = {
|
|
230
|
+
content,
|
|
231
|
+
ast: content,
|
|
232
|
+
ext: type ? '' : '.js',
|
|
233
|
+
type,
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
const detective = getDetector(fileInfo, normalizedOptions) || getJsDetector(fileInfo, normalizedOptions);
|
|
237
|
+
if (!detective) {
|
|
238
|
+
return [];
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const deps = detective(fileInfo.ast, normalizedOptions[fileInfo.type]);
|
|
242
|
+
// @ts-ignore
|
|
243
|
+
precinct.ast = detective.ast || fileInfo.ast;
|
|
244
|
+
|
|
245
|
+
return deps;
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
precinct.paperwork = getDepsFromFile;
|
|
249
|
+
|
|
250
|
+
export default precinct;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ImportSpecifier } from '@teambit/legacy/dist/consumer/component/dependencies/dependency';
|
|
2
|
+
import { ResolvedPackageData } from '../../resolve-pkg-data';
|
|
3
|
+
import { DependencyDetector } from '../detector-hook';
|
|
4
|
+
import { isEmpty } from 'lodash';
|
|
5
|
+
|
|
6
|
+
export type FileObject = {
|
|
7
|
+
file: string;
|
|
8
|
+
importSpecifiers?: ImportSpecifier[];
|
|
9
|
+
importSource?: string;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
type MissingType = 'files' | 'packages';
|
|
13
|
+
|
|
14
|
+
export class DependenciesTreeItem {
|
|
15
|
+
files: FileObject[] = [];
|
|
16
|
+
packages: { [packageName: string]: string } = {}; // pkgName: pkgVersion
|
|
17
|
+
unidentifiedPackages: string[] = [];
|
|
18
|
+
components: ResolvedPackageData[] = [];
|
|
19
|
+
error?: Error; // error.code is either PARSING_ERROR or RESOLVE_ERROR
|
|
20
|
+
missing?: { [key in MissingType]: string[] };
|
|
21
|
+
|
|
22
|
+
isEmpty() {
|
|
23
|
+
return (
|
|
24
|
+
!this.files.length &&
|
|
25
|
+
isEmpty(this.packages) &&
|
|
26
|
+
!this.unidentifiedPackages.length &&
|
|
27
|
+
!this.components.length &&
|
|
28
|
+
!this.error &&
|
|
29
|
+
!this.missing
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export type DependenciesTree = {
|
|
35
|
+
[filePath: string]: DependenciesTreeItem;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export type DependencyTreeParams = {
|
|
39
|
+
componentDir: string;
|
|
40
|
+
workspacePath: string;
|
|
41
|
+
filePaths: string[];
|
|
42
|
+
visited?: Record<string, any>;
|
|
43
|
+
cacheResolvedDependencies?: Record<string, any>;
|
|
44
|
+
cacheProjectAst?: Record<string, any>;
|
|
45
|
+
envDetectors?: DependencyDetector[] | null;
|
|
46
|
+
};
|