Following its logic, the only possible way (I believe) would be to "scan" all the components required for the application to run.
In architecture:
src
|---components
|---com1
\--> export function com1();
|---com2
\--> export function com4();
|---com3
\--> export function com4();
|---com4
\--> export function com4();
index.ts
Inside index if you do
export * from './components/com1'
export * from './components/com2'
export * from './components/com3'
export * from './components/com4'
console.log(Object.keys(this));
console.log(hasAllExportFunctionExists(this));
function hasAllExportFunctionExists(objectStruct: any) {
let exportedDeparaRequired = [
"com1",
"com2",
"com3",
"com4"
];
return Object.keys(objectStruct).every(v => exportedDeparaRequired.includes(v));
}
With your tsconfig.json this way:
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"lib": [
"dom",
"es6",
"es2017",
"esnext.asynciterable"
],
"sourceMap": true,
"outDir": "./build",
"moduleResolution": "node",
"removeComments": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"noImplicitThis": true,
"noUnusedLocals": false,
"noUnusedParameters": false,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"baseUrl": "./"
},
"exclude": [
"node_modules"
],
"include": [
"./src/**/*.ts"
]
}
the tsc
will compile to something like this:
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./components/com1"));
__export(require("./components/com2"));
__export(require("./components/com3"));
__export(require("./components/com4"));
console.log(Object.keys(this));
hasAllExportFunctionExists(this);
function hasAllExportFunctionExists(objectStruct) {
let exportedDeparaRequired = [
"com1",
"com2",
"com3",
"com4"
];
return Object.keys(objectStruct).every(v => exportedDeparaRequired.includes(v));
}
What will return in "Node index.js"
['com1', 'com2', 'com3', 'com4' ]
true
You want to check which members are being exported or the
import
statements itself? Try to edit your question to make it clearer.– Luiz Felipe
@Luizfelipe edited the question, I could see if it gave an improved?
– Felipe Avelar
Hello dear Felipe, I understand the motivation of the question as a question of evaluation of the state of the program, I just do not think it feasible to do this in practice, force load all components, I think the components should be isolated and that is why there is import, calling only what is needed, doing an over of everything seems to be overloading the current process without need. Maybe I misunderstood something, could explain the purpose?
– Guilherme Nascimento
@Guilhermenascimento in the case, would not carry all the components. The context is that I am creating a package of components, hence my index serves to export the components, only, in one of the versions, I had forgotten to put the export in index and this component was not visible to those who installed the package, hence I want to create?
– Felipe Avelar
Check out if this does not help you: https://stackoverflow.com/a/40703602/3021610
– Aníbal Duarte