@adhd/decompile-cli 0.1.7
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/README.md +175 -0
- package/bin/decompile.d.ts +2 -0
- package/bin/decompile.js +89 -0
- package/bin/decompile.js.map +1 -0
- package/package.json +35 -0
- package/src/index.d.ts +1 -0
- package/src/index.js +2 -0
- package/src/index.js.map +1 -0
- package/src/lib/extractors/index.d.ts +10 -0
- package/src/lib/extractors/index.js +228 -0
- package/src/lib/extractors/index.js.map +1 -0
- package/src/lib/extractors/local-file.d.ts +5 -0
- package/src/lib/extractors/local-file.js +22 -0
- package/src/lib/extractors/local-file.js.map +1 -0
- package/src/lib/extractors/map.d.ts +6 -0
- package/src/lib/extractors/map.js +74 -0
- package/src/lib/extractors/map.js.map +1 -0
- package/src/lib/extractors/raw-html.d.ts +7 -0
- package/src/lib/extractors/raw-html.js +93 -0
- package/src/lib/extractors/raw-html.js.map +1 -0
- package/src/lib/extractors/site.d.ts +34 -0
- package/src/lib/extractors/site.js +96 -0
- package/src/lib/extractors/site.js.map +1 -0
- package/src/lib/index.d.ts +8 -0
- package/src/lib/index.js +6 -0
- package/src/lib/index.js.map +1 -0
- package/src/lib/pipeline/index.d.ts +1 -0
- package/src/lib/pipeline/index.js +2 -0
- package/src/lib/pipeline/index.js.map +1 -0
- package/src/lib/pipeline/pipes/resolver/actions.d.ts +14 -0
- package/src/lib/pipeline/pipes/resolver/actions.js +50 -0
- package/src/lib/pipeline/pipes/resolver/actions.js.map +1 -0
- package/src/lib/pipeline/pipes/resolver/index.d.ts +1 -0
- package/src/lib/pipeline/pipes/resolver/index.js +2 -0
- package/src/lib/pipeline/pipes/resolver/index.js.map +1 -0
- package/src/lib/pipeline/stack.d.ts +23 -0
- package/src/lib/pipeline/stack.js +45 -0
- package/src/lib/pipeline/stack.js.map +1 -0
- package/src/lib/store/build.d.ts +2 -0
- package/src/lib/store/build.js +50 -0
- package/src/lib/store/build.js.map +1 -0
- package/src/lib/store/index.d.ts +92 -0
- package/src/lib/store/index.js +127 -0
- package/src/lib/store/index.js.map +1 -0
- package/src/lib/store/package.d.ts +60 -0
- package/src/lib/store/package.js +114 -0
- package/src/lib/store/package.js.map +1 -0
- package/src/lib/store/templates.d.ts +84 -0
- package/src/lib/store/templates.js +78 -0
- package/src/lib/store/templates.js.map +1 -0
- package/src/lib/store/utils.d.ts +3 -0
- package/src/lib/store/utils.js +8 -0
- package/src/lib/store/utils.js.map +1 -0
- package/src/lib/validators/index.d.ts +2 -0
- package/src/lib/validators/index.js +7 -0
- package/src/lib/validators/index.js.map +1 -0
- package/src/lib/validators/local/index.d.ts +31 -0
- package/src/lib/validators/local/index.js +93 -0
- package/src/lib/validators/local/index.js.map +1 -0
- package/src/lib/validators/local/isBase64.d.ts +2 -0
- package/src/lib/validators/local/isBase64.js +11 -0
- package/src/lib/validators/local/isBase64.js.map +1 -0
- package/src/lib/validators/local/isCSS.d.ts +2 -0
- package/src/lib/validators/local/isCSS.js +15 -0
- package/src/lib/validators/local/isCSS.js.map +1 -0
- package/src/lib/validators/local/isHTML.d.ts +2 -0
- package/src/lib/validators/local/isHTML.js +13 -0
- package/src/lib/validators/local/isHTML.js.map +1 -0
- package/src/lib/validators/local/isJS.d.ts +2 -0
- package/src/lib/validators/local/isJS.js +28 -0
- package/src/lib/validators/local/isJS.js.map +1 -0
- package/src/lib/validators/local/isJson.d.ts +2 -0
- package/src/lib/validators/local/isJson.js +40 -0
- package/src/lib/validators/local/isJson.js.map +1 -0
- package/src/lib/validators/local/isSourceMap.d.ts +11 -0
- package/src/lib/validators/local/isSourceMap.js +57 -0
- package/src/lib/validators/local/isSourceMap.js.map +1 -0
- package/src/lib/validators/url/errors.d.ts +9 -0
- package/src/lib/validators/url/errors.js +36 -0
- package/src/lib/validators/url/errors.js.map +1 -0
- package/src/lib/validators/url/index.d.ts +32 -0
- package/src/lib/validators/url/index.js +231 -0
- package/src/lib/validators/url/index.js.map +1 -0
package/README.md
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
## @adhd/decompile-cli
|
|
2
|
+
|
|
3
|
+
Reverse is a tool for reverse engineering code bundled with source maps.
|
|
4
|
+
Reverse accepts
|
|
5
|
+
**(remote) urls:** html, js, css, map, json
|
|
6
|
+
**(local) files:** html, js, ts, jsx..., css, etc
|
|
7
|
+
|
|
8
|
+
### Install
|
|
9
|
+
|
|
10
|
+
`npm install -g @adhd/decompile-cli`
|
|
11
|
+
`yarn global add @adhd/decompile-cli`
|
|
12
|
+
|
|
13
|
+
### Usage
|
|
14
|
+
|
|
15
|
+
To run in reverse, you have to supply a reference to the target. It can be in the form of a `url`, `domain`, or local `files`.
|
|
16
|
+
|
|
17
|
+
**currently supported types** (remote and local)
|
|
18
|
+
|
|
19
|
+
- `html` extracts references (css, js)
|
|
20
|
+
- `js*` extracts references (map, js deps)
|
|
21
|
+
- `css` extracts references (map)
|
|
22
|
+
- `map` uses the map to rebuild source code (src, fs, deps)
|
|
23
|
+
- `json` currently checks to see if the json is a map
|
|
24
|
+
|
|
25
|
+
Run with
|
|
26
|
+
|
|
27
|
+
`npx @adhd/decompile-cli deps`
|
|
28
|
+
|
|
29
|
+
or
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
> npx @adhd/decompile-cli reverse -h
|
|
33
|
+
|
|
34
|
+
Usage: reverse
|
|
35
|
+
Usage: [options] <sources...>
|
|
36
|
+
|
|
37
|
+
Example: > npx @adhd/decompile-cli reverse -o ./<output_directory> "https://<url_to_examine>" "./source.{html,js,css,map}"
|
|
38
|
+
|
|
39
|
+
crawl and extract source maps
|
|
40
|
+
|
|
41
|
+
Options:
|
|
42
|
+
-V, --version output the version number
|
|
43
|
+
-o <output> (optional) directory to write the source into
|
|
44
|
+
-h, --help output usage information
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
#### CLI
|
|
48
|
+
|
|
49
|
+
`<sources...>` (required) one or more `urls` and or `file_paths`
|
|
50
|
+
|
|
51
|
+
`-o <output_dir>`
|
|
52
|
+
|
|
53
|
+
#### Pipeline
|
|
54
|
+
|
|
55
|
+
**with url for source arg**
|
|
56
|
+
|
|
57
|
+
request url
|
|
58
|
+
-> extract asset refs
|
|
59
|
+
-> request assets
|
|
60
|
+
-> extract source map references
|
|
61
|
+
-> request maps
|
|
62
|
+
-> reverse map the assets
|
|
63
|
+
-> dump source code
|
|
64
|
+
-> reverse the external dependencies
|
|
65
|
+
-> reconstruct entry point
|
|
66
|
+
|
|
67
|
+
For local files the pipeline skips to the 4th step
|
|
68
|
+
For source maps it skips to the 6th line
|
|
69
|
+
|
|
70
|
+
# @adhd/decompile-cli
|
|
71
|
+
|
|
72
|
+
reverse is a tool for reverse engineering code bundled with source maps.
|
|
73
|
+
reverse accepts
|
|
74
|
+
|
|
75
|
+
- **(remote) urls:** html, js, css, map, json
|
|
76
|
+
|
|
77
|
+
- **(local) files:** html, js, ts, jsx..., css, etc
|
|
78
|
+
|
|
79
|
+
## Getting Started
|
|
80
|
+
|
|
81
|
+
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.
|
|
82
|
+
|
|
83
|
+
### Prerequisites
|
|
84
|
+
|
|
85
|
+
What things you need to install the software and how to install them
|
|
86
|
+
|
|
87
|
+
```
|
|
88
|
+
Give examples
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Installing
|
|
92
|
+
|
|
93
|
+
A step by step series of examples that tell you how to get a development env running
|
|
94
|
+
|
|
95
|
+
With `npm`
|
|
96
|
+
|
|
97
|
+
```sh
|
|
98
|
+
npm install -g @adhd/decompile-cli
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
With `npx`
|
|
102
|
+
|
|
103
|
+
```sh
|
|
104
|
+
npx @adhd/decompile-cli <...>
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
With `yarn`
|
|
108
|
+
|
|
109
|
+
```
|
|
110
|
+
yarn global add @adhd/decompile-cli
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
End with an example of getting some data out of the system or using it for a little demo
|
|
114
|
+
|
|
115
|
+
## Running the tests
|
|
116
|
+
|
|
117
|
+
`ava` or `yarn test`
|
|
118
|
+
|
|
119
|
+
### Break down into end to end tests
|
|
120
|
+
|
|
121
|
+
In [src/validators/local/**tests**](./src/validators/local/__tests__) each of the pattern matching utilities are tested
|
|
122
|
+
|
|
123
|
+
The data mocks are in [tests/fixtures](./tests/fixtures)
|
|
124
|
+
|
|
125
|
+
EX: [base64.sourcemap.js](./tests/fixtures/base64.sourcemap.js)
|
|
126
|
+
|
|
127
|
+
```js
|
|
128
|
+
).apply(__cjsWrapper.exports, __cjsWrapper.args);
|
|
129
|
+
}
|
|
130
|
+
)(System, System);
|
|
131
|
+
//# sourceURL=module://App.js.js!transpiled
|
|
132
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm1vZHVsZTovL0FwcC5q...
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### And coding style tests
|
|
136
|
+
|
|
137
|
+
Explain what these tests test and why
|
|
138
|
+
|
|
139
|
+
```
|
|
140
|
+
Give an example
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## Deployment
|
|
144
|
+
|
|
145
|
+
Add additional notes about how to deploy this on a live system
|
|
146
|
+
|
|
147
|
+
## Built With
|
|
148
|
+
|
|
149
|
+
- [Dropwizard](http://www.dropwizard.io/1.0.2/docs/) - The web framework used
|
|
150
|
+
- [Maven](https://maven.apache.org/) - Dependency Management
|
|
151
|
+
- [ROME](https://rometools.github.io/rome/) - Used to generate RSS Feeds
|
|
152
|
+
|
|
153
|
+
## Contributing
|
|
154
|
+
|
|
155
|
+
Please read [CONTRIBUTING.md](https://gist.github.com/PurpleBooth/b24679402957c63ec426) for details on our code of conduct, and the process for submitting pull requests to us.
|
|
156
|
+
|
|
157
|
+
## Versioning
|
|
158
|
+
|
|
159
|
+
We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/your/project/tags).
|
|
160
|
+
|
|
161
|
+
## Authors
|
|
162
|
+
|
|
163
|
+
- **Billie Thompson** - _Initial work_ - [PurpleBooth](https://github.com/PurpleBooth)
|
|
164
|
+
|
|
165
|
+
See also the list of [contributors](https://github.com/your/project/contributors) who participated in this project.
|
|
166
|
+
|
|
167
|
+
## License
|
|
168
|
+
|
|
169
|
+
This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details
|
|
170
|
+
|
|
171
|
+
## Acknowledgments
|
|
172
|
+
|
|
173
|
+
- Hat tip to anyone whose code was used
|
|
174
|
+
- Inspiration
|
|
175
|
+
- etc
|
package/bin/decompile.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
import { Extractors, FileStore } from '../src/index.js';
|
|
4
|
+
function collect(value, previous) {
|
|
5
|
+
return previous.concat([value]);
|
|
6
|
+
}
|
|
7
|
+
const program = new Command();
|
|
8
|
+
program
|
|
9
|
+
.command('reverse')
|
|
10
|
+
.version('0.0.1')
|
|
11
|
+
.description('crawl and extract source maps')
|
|
12
|
+
.option('-o, --output <path>', 'output path', 'decompiled')
|
|
13
|
+
.arguments('[sources...]')
|
|
14
|
+
.usage(`
|
|
15
|
+
${program.helpInformation().split('\n')[0]}
|
|
16
|
+
|
|
17
|
+
Example:
|
|
18
|
+
adhd -o ./output "https://example.com" "./source.{html,js,css,map}"
|
|
19
|
+
`)
|
|
20
|
+
.action(async (sources, _, tops) => {
|
|
21
|
+
const allSources = sources;
|
|
22
|
+
try {
|
|
23
|
+
const res = await Extractors.testpipeline(allSources, tops.output);
|
|
24
|
+
console.log('finished', { ...res });
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
console.error('failed', { error: e });
|
|
28
|
+
process.exit(1);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
program
|
|
32
|
+
.command('deps')
|
|
33
|
+
.version('0.0.1')
|
|
34
|
+
.description('get deps from path')
|
|
35
|
+
.option('-a, --allowModule <module>', 'allow only specific node_modules', collect, [])
|
|
36
|
+
.option('-x, --excludeModule <module>', 'exclude specific node_modules', collect, [])
|
|
37
|
+
.option('-m, --allowAllModules', 'allow all node_modules')
|
|
38
|
+
.option('-e, --excludeRegex <regex>', 'regex to match paths for exclusion')
|
|
39
|
+
.option('-i, --includeRegex <regex>', 'regex to match paths for inclusion')
|
|
40
|
+
.option('-j, --json', 'output json string')
|
|
41
|
+
.usage(`<source...>
|
|
42
|
+
|
|
43
|
+
Example:
|
|
44
|
+
adhd-deps "libs/my-lib/src" | jq .unimported`)
|
|
45
|
+
.argument('<source...>', 'entry point + optional src dirs')
|
|
46
|
+
.action(async (sources, opts) => {
|
|
47
|
+
const options = {
|
|
48
|
+
exclude: {
|
|
49
|
+
path: '.*(node_modules).*',
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
// precedence logic (same as your original)
|
|
53
|
+
if (opts.exclude?.length) {
|
|
54
|
+
options.exclude = {
|
|
55
|
+
path: `.*(node_modules\\/(${opts.exclude.join('|')})\\/).*`,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
else if (opts.include?.length) {
|
|
59
|
+
options.exclude = {
|
|
60
|
+
path: `.*(?!node_modules\\/(?:${opts.include.join('|')})\\/)node_modules\\/.*`,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
else if (opts.allowModules) {
|
|
64
|
+
delete options.exclude;
|
|
65
|
+
}
|
|
66
|
+
if (opts.excludeRegex) {
|
|
67
|
+
options.exclude = {
|
|
68
|
+
path: opts.excludeRegex,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
if (opts.includeRegex) {
|
|
72
|
+
options.includeOnly = opts.includeRegex;
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
const data = await FileStore.getDeps(sources, options);
|
|
76
|
+
if (opts.json) {
|
|
77
|
+
console.log(JSON.stringify(data, null, 2));
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
console.log(data);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
catch (err) {
|
|
84
|
+
console.error('failed', err);
|
|
85
|
+
process.exit(1);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
await program.parseAsync(process.argv);
|
|
89
|
+
//# sourceMappingURL=decompile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decompile.js","sourceRoot":"","sources":["../../bin/decompile.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAExD,SAAS,OAAO,CAAC,KAAa,EAAE,QAAkB;IAChD,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;AAClC,CAAC;AAED,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;AAE9B,OAAO;KACJ,OAAO,CAAC,SAAS,CAAC;KAClB,OAAO,CAAC,OAAO,CAAC;KAChB,WAAW,CAAC,+BAA+B,CAAC;KAC5C,MAAM,CAAC,qBAAqB,EAAE,aAAa,EAAE,YAAY,CAAC;KAC1D,SAAS,CAAC,cAAc,CAAC;KACzB,KAAK,CACJ;EACF,OAAO,CAAC,eAAe,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;;;;CAIzC,CACE;KACA,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE;IACjC,MAAM,UAAU,GAAG,OAAO,CAAC;IAE3B,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,MAAM,UAAU,CAAC,YAAY,CAAC,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QACnE,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,EAAE,GAAG,GAAG,EAAE,CA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GAAG,CACJ,wBAAwB;SAC1B,CAAC;IACJ,CAAC;SAAM,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;QAC7B,OAAO,OAAO,CAAC,OAAO,CAAC;IACzB,CAAC;IAED,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;QACtB,OAAO,CAAC,OAAO,GAAG;YAChB,IAAI,EAAE,IAAI,CAAC,YAAY;SACxB,CAAC;IACJ,CAAC;IAED,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;QACtB,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,YAAY,CAAC;IAC1C,CAAC;IAED,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,MAAM,SAAS,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAEvD,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YACd,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;QAC7C,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACpB,CAAC;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;QAC7B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC,CAAC,CAAC;AACL,MAAM,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC","sourcesContent":["#!/usr/bin/env node\n\nimport { Command } from 'commander';\nimport { Extractors, FileStore } from '../src/index.js';\n\nfunction collect(value: string, previous: string[]) {\n return previous.concat([value]);\n}\n\nconst program = new Command();\n\nprogram\n .command('reverse')\n .version('0.0.1')\n .description('crawl and extract source maps')\n .option('-o, --output <path>', 'output path', 'decompiled')\n .arguments('[sources...]')\n .usage(\n `\n${program.helpInformation().split('\\n')[0]}\n\nExample:\n adhd -o ./output \"https://example.com\" \"./source.{html,js,css,map}\"\n`\n )\n .action(async (sources, _, tops) => {\n const allSources = sources;\n\n try {\n const res = await Extractors.testpipeline(allSources, tops.output);\n console.log('finished', { ...res });\n } catch (e) {\n console.error('failed', { error: e });\n process.exit(1);\n }\n });\n\nprogram\n .command('deps')\n .version('0.0.1')\n .description('get deps from path')\n\n .option(\n '-a, --allowModule <module>',\n 'allow only specific node_modules',\n collect,\n []\n )\n .option(\n '-x, --excludeModule <module>',\n 'exclude specific node_modules',\n collect,\n []\n )\n .option('-m, --allowAllModules', 'allow all node_modules')\n .option('-e, --excludeRegex <regex>', 'regex to match paths for exclusion')\n .option('-i, --includeRegex <regex>', 'regex to match paths for inclusion')\n .option('-j, --json', 'output json string')\n .usage(\n `<source...>\n \n Example:\n adhd-deps \"libs/my-lib/src\" | jq .unimported`\n )\n .argument('<source...>', 'entry point + optional src dirs')\n .action(async (sources: string[], opts) => {\n const options: { exclude?: { path: string }; includeOnly?: string } = {\n exclude: {\n path: '.*(node_modules).*',\n },\n };\n\n // precedence logic (same as your original)\n if (opts.exclude?.length) {\n options.exclude = {\n path: `.*(node_modules\\\\/(${opts.exclude.join('|')})\\\\/).*`,\n };\n } else if (opts.include?.length) {\n options.exclude = {\n path: `.*(?!node_modules\\\\/(?:${opts.include.join(\n '|'\n )})\\\\/)node_modules\\\\/.*`,\n };\n } else if (opts.allowModules) {\n delete options.exclude;\n }\n\n if (opts.excludeRegex) {\n options.exclude = {\n path: opts.excludeRegex,\n };\n }\n\n if (opts.includeRegex) {\n options.includeOnly = opts.includeRegex;\n }\n\n try {\n const data = await FileStore.getDeps(sources, options);\n\n if (opts.json) {\n console.log(JSON.stringify(data, null, 2));\n } else {\n console.log(data);\n }\n } catch (err) {\n console.error('failed', err);\n process.exit(1);\n }\n });\nawait program.parseAsync(process.argv);\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@adhd/decompile-cli",
|
|
3
|
+
"version": "0.1.7",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./src/index.js",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"bin": {
|
|
10
|
+
"decompile": "./bin/decompile.js"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"acorn": "^8.14.1",
|
|
14
|
+
"acorn-jsx": "^5.3.2",
|
|
15
|
+
"adm-zip": "^0.5.16",
|
|
16
|
+
"async-request": "^1.2.0",
|
|
17
|
+
"babel-polyfill": "^6.26.0",
|
|
18
|
+
"cheerio": "^1.2.0",
|
|
19
|
+
"commander": "14.0.3",
|
|
20
|
+
"depcheck": "^1.4.7",
|
|
21
|
+
"dependency-cruiser": "^17.3.9",
|
|
22
|
+
"fs-extra": "11.2.0",
|
|
23
|
+
"language-detect": "^1.1.0",
|
|
24
|
+
"lodash": "4.17.21",
|
|
25
|
+
"postcss": "^8.5.3",
|
|
26
|
+
"posthtml-parser": "^0.12.1",
|
|
27
|
+
"source-map": "0.6.1",
|
|
28
|
+
"tough-cookie": "4.1.4",
|
|
29
|
+
"tslib": "^2.3.0",
|
|
30
|
+
"util": "0.12.5",
|
|
31
|
+
"@babel/register": "7.29.7",
|
|
32
|
+
"react": "18.2.0",
|
|
33
|
+
"@adhd/data-base-transforms": "^2.2.1"
|
|
34
|
+
}
|
|
35
|
+
}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './lib/index.js';
|
package/src/index.js
ADDED
package/src/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC","sourcesContent":["export * from './lib/index.js';\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import Stack from '../pipeline/stack.js';
|
|
2
|
+
export declare const extract: (callStack: Stack) => Promise<void>;
|
|
3
|
+
export declare const testpipeline: (files: string[], prefix: string) => Promise<import("../store/index.js").WriteOperations[]>;
|
|
4
|
+
export declare const pipeline: (input: string, prefix?: string) => Promise<import("../store/index.js").WriteOperations>;
|
|
5
|
+
declare const Extractors: {
|
|
6
|
+
testpipeline: (files: string[], prefix: string) => Promise<import("../store/index.js").WriteOperations[]>;
|
|
7
|
+
pipeline: (input: string, prefix?: string) => Promise<import("../store/index.js").WriteOperations>;
|
|
8
|
+
extract: (callStack: Stack) => Promise<void>;
|
|
9
|
+
};
|
|
10
|
+
export default Extractors;
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { Transform } from '@adhd/data-base-transforms';
|
|
2
|
+
import Stack from '../pipeline/stack.js';
|
|
3
|
+
import Store from '../store/index.js';
|
|
4
|
+
import extractLocal from './local-file.js';
|
|
5
|
+
import { extractMapLink, extractSource } from './map.js';
|
|
6
|
+
import { extractRawHtml, isHtml } from './raw-html.js';
|
|
7
|
+
import extractSite from './site.js';
|
|
8
|
+
export const extract = async (callStack) => {
|
|
9
|
+
const item = callStack.pop();
|
|
10
|
+
if (!callStack.hasMore() || item === null)
|
|
11
|
+
return;
|
|
12
|
+
const [type, input] = item;
|
|
13
|
+
if (input === null)
|
|
14
|
+
return;
|
|
15
|
+
console.log(`Extract[${type}]`, {
|
|
16
|
+
input: input.path && input.path?.includes('.js') ? input : input.path,
|
|
17
|
+
});
|
|
18
|
+
try {
|
|
19
|
+
if (!!callStack && input) {
|
|
20
|
+
let r;
|
|
21
|
+
if (type === 'site') {
|
|
22
|
+
/*
|
|
23
|
+
* desc: url of website to crawl
|
|
24
|
+
* input: str
|
|
25
|
+
*/
|
|
26
|
+
try {
|
|
27
|
+
const res = await extractSite(input.path);
|
|
28
|
+
console.log({ site: res });
|
|
29
|
+
if (res) {
|
|
30
|
+
if (res.path.endsWith('.js')) {
|
|
31
|
+
callStack.push('link', res);
|
|
32
|
+
}
|
|
33
|
+
if (res.path.endsWith('.map')) {
|
|
34
|
+
callStack.push('map', {
|
|
35
|
+
path: res.path,
|
|
36
|
+
data: '',
|
|
37
|
+
mapping: res.data,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
callStack.push('raw', res);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
catch (e) {
|
|
46
|
+
console.error('extract site error:', Stack, e);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
else if (type === 'local') {
|
|
50
|
+
/*
|
|
51
|
+
* desc: file or dir path of local source files
|
|
52
|
+
* input: str
|
|
53
|
+
*/
|
|
54
|
+
r = extractLocal(input.path);
|
|
55
|
+
if (r?.path.endsWith('.html')) {
|
|
56
|
+
callStack.push('raw', r);
|
|
57
|
+
}
|
|
58
|
+
else if (r?.path.endsWith('.map')) {
|
|
59
|
+
callStack.push('map', {
|
|
60
|
+
path: r.path,
|
|
61
|
+
data: '',
|
|
62
|
+
mapping: r.data,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
else if (r) {
|
|
66
|
+
callStack.push('source', r);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else if (type === 'raw') {
|
|
70
|
+
/*
|
|
71
|
+
* desc: raw html from website to extract links
|
|
72
|
+
* input: str
|
|
73
|
+
*/
|
|
74
|
+
r = extractRawHtml(input);
|
|
75
|
+
console.log({ links: r });
|
|
76
|
+
r.forEach((l) => {
|
|
77
|
+
callStack.push('link', { path: l, data: '' });
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
else if (type === 'link') {
|
|
81
|
+
/*
|
|
82
|
+
* all requested js, css, etc should start here
|
|
83
|
+
* desc: url of the extracted source
|
|
84
|
+
* input: str
|
|
85
|
+
*/
|
|
86
|
+
try {
|
|
87
|
+
r = await extractSite(input.path);
|
|
88
|
+
if (r) {
|
|
89
|
+
// console.log({ res: r })
|
|
90
|
+
if (input.path.endsWith('.map')) {
|
|
91
|
+
callStack.push('map', {
|
|
92
|
+
path: r.path,
|
|
93
|
+
data: '',
|
|
94
|
+
mapping: r.data,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
callStack.push('source', r);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
catch (e) {
|
|
103
|
+
console.error(e);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
else if (type === 'source' && Transform.isString(input)) {
|
|
107
|
+
/*
|
|
108
|
+
* desc: raw text from the requested link
|
|
109
|
+
* input: <str>
|
|
110
|
+
*/
|
|
111
|
+
r = extractMapLink(input);
|
|
112
|
+
if (r && r.length) {
|
|
113
|
+
console.log('EXTRACT[source] map link', r);
|
|
114
|
+
r.forEach((l) => callStack.push('link', { path: l, data: '' }));
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
callStack.push('write', { path: input.path, data: input.data });
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
else if (type === 'map' && !Transform.isString(input)) {
|
|
121
|
+
/*
|
|
122
|
+
* desc: raw source map
|
|
123
|
+
* input: json
|
|
124
|
+
*/
|
|
125
|
+
try {
|
|
126
|
+
if (!input.mapping)
|
|
127
|
+
throw Error('Mapping missing');
|
|
128
|
+
r = await extractSource(input.mapping).then((res) => {
|
|
129
|
+
res?.forEach((src) => {
|
|
130
|
+
callStack.push('write', src);
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
// console.log({ map: r })
|
|
134
|
+
}
|
|
135
|
+
catch (e) {
|
|
136
|
+
console.error(e);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
else if (type === 'write') {
|
|
140
|
+
/*
|
|
141
|
+
* desc=source and map files to write
|
|
142
|
+
* input=[{"name": str, "data": json}]
|
|
143
|
+
*/
|
|
144
|
+
Store.addToImports(input.path);
|
|
145
|
+
Store.addFile(input.path, input.data);
|
|
146
|
+
// if(Transform.isArray(input)){
|
|
147
|
+
// fs.writeJSONSync(f.name, f.data)
|
|
148
|
+
// });
|
|
149
|
+
// }
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
catch (e) {
|
|
154
|
+
console.error('EXTRACT[catchall]', e);
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
const run = async (callStack) => {
|
|
158
|
+
while (callStack.hasMore()) {
|
|
159
|
+
await extract(callStack);
|
|
160
|
+
if (callStack.isEmpty()) {
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
await Store.finalize();
|
|
165
|
+
};
|
|
166
|
+
export const testpipeline = (files, prefix) => {
|
|
167
|
+
console.log({ files, prefix });
|
|
168
|
+
return Promise.all(files.map((f) => {
|
|
169
|
+
console.log(`pipeline started: ${f}`);
|
|
170
|
+
return pipeline(f, prefix);
|
|
171
|
+
})).then((r) => {
|
|
172
|
+
console.log('complete');
|
|
173
|
+
return r;
|
|
174
|
+
// console.log('finalizing package.json + index.js');
|
|
175
|
+
// return Store.finalize()
|
|
176
|
+
});
|
|
177
|
+
// .then(() => {
|
|
178
|
+
// });
|
|
179
|
+
// return argz
|
|
180
|
+
};
|
|
181
|
+
import { constants } from 'fs';
|
|
182
|
+
import { access } from 'fs/promises';
|
|
183
|
+
async function fileExists(path) {
|
|
184
|
+
try {
|
|
185
|
+
await access(path, constants.F_OK);
|
|
186
|
+
return true;
|
|
187
|
+
}
|
|
188
|
+
catch {
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
/* EXAMPLE:
|
|
193
|
+
*
|
|
194
|
+
* pipeline('./maps/bitbucket/app.f606c0f20e8744e93489.js.map',
|
|
195
|
+
* './build/test','map').then(() => console.log('complete'))
|
|
196
|
+
*/
|
|
197
|
+
export const pipeline = async (input, prefix = './build/src') => {
|
|
198
|
+
const callStack = new Stack();
|
|
199
|
+
Store.setPrefix(prefix);
|
|
200
|
+
// pkg="test"
|
|
201
|
+
// Store.package=pkg
|
|
202
|
+
if (typeof input === 'string' && input.startsWith('http')) {
|
|
203
|
+
if (input.endsWith('js')) {
|
|
204
|
+
callStack.push('link', { path: input, data: '' });
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
callStack.push('site', { path: input, data: '' });
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
else if (await fileExists(input)) {
|
|
211
|
+
callStack.push('local', { path: input, data: '' });
|
|
212
|
+
}
|
|
213
|
+
else if (isHtml(input)) {
|
|
214
|
+
callStack.push('raw', { path: input, data: '' });
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
console.log('couldnt find ' + input);
|
|
218
|
+
}
|
|
219
|
+
await run(callStack);
|
|
220
|
+
return Store.finalize();
|
|
221
|
+
};
|
|
222
|
+
const Extractors = {
|
|
223
|
+
testpipeline,
|
|
224
|
+
pipeline,
|
|
225
|
+
extract,
|
|
226
|
+
};
|
|
227
|
+
export default Extractors;
|
|
228
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/extractors/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,KAAK,MAAM,sBAAsB,CAAC;AACzC,OAAO,KAAK,MAAM,mBAAmB,CAAC;AACtC,OAAO,YAAY,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,WAAW,MAAM,WAAW,CAAC;AAEpC,MAAM,CAAC,MAAM,OAAO,GAAG,KAAK,EAAE,SAAgB,EAAE,EAAE;IAChD,MAAM,IAAI,GAAG,SAAS,CAAC,GAAG,EAAE,CAAC;IAC7B,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,IAAI,KAAK,IAAI;QAAE,OAA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M,CAAC,EAAE,CAAC;QAC1D,IAAI,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;YACzB,SAAS,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;QACpD,CAAC;aAAM,CAAC;YACN,SAAS,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;QACpD,CAAC;IACH,CAAC;SAAM,IAAI,MAAM,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;QACnC,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;IACrD,CAAC;SAAM,IAAI,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,SAAS,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;IACnD,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,GAAG,CAAC,eAAe,GAAG,KAAK,CAAC,CAAC;IACvC,CAAC;IACD,MAAM,GAAG,CAAC,SAAS,CAAC,CAAC;IACrB,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;AAC1B,CAAC,CAAC;AAEF,MAAM,UAAU,GAAG;IACjB,YAAY;IACZ,QAAQ;IACR,OAAO;CACR,CAAC;AAEF,eAAe,UAAU,CAAC","sourcesContent":["import { Transform } from '@adhd/data-base-transforms';\nimport Stack from '../pipeline/stack.js';\nimport Store from '../store/index.js';\nimport extractLocal from './local-file.js';\nimport { extractMapLink, extractSource } from './map.js';\nimport { extractRawHtml, isHtml } from './raw-html.js';\nimport extractSite from './site.js';\n\nexport const extract = async (callStack: Stack) => {\n const item = callStack.pop();\n if (!callStack.hasMore() || item === null) return;\n\n const [type, input] = item;\n if (input === null) return;\n console.log(`Extract[${type}]`, {\n input: input.path && input.path?.includes('.js') ? input : input.path,\n });\n try {\n if (!!callStack && input) {\n let r;\n if (type === 'site') {\n /*\n * desc: url of website to crawl\n * input: str\n */\n try {\n const res = await extractSite(input.path);\n console.log({ site: res });\n if (res) {\n if (res.path.endsWith('.js')) {\n callStack.push('link', res);\n }\n if (res.path.endsWith('.map')) {\n callStack.push('map', {\n path: res.path,\n data: '',\n mapping: res.data,\n });\n } else {\n callStack.push('raw', res);\n }\n }\n } catch (e) {\n console.error('extract site error:', Stack, e);\n }\n } else if (type === 'local') {\n /*\n * desc: file or dir path of local source files\n * input: str\n */\n r = extractLocal(input.path);\n if (r?.path.endsWith('.html')) {\n callStack.push('raw', r);\n } else if (r?.path.endsWith('.map')) {\n callStack.push('map', {\n path: r.path,\n data: '',\n mapping: r.data as unknown as RawSourceMap,\n });\n } else if (r) {\n callStack.push('source', r);\n }\n } else if (type === 'raw') {\n /*\n * desc: raw html from website to extract links\n * input: str\n */\n\n r = extractRawHtml(input);\n console.log({ links: r });\n r.forEach((l) => {\n callStack.push('link', { path: l, data: '' });\n });\n } else if (type === 'link') {\n /*\n * all requested js, css, etc should start here\n * desc: url of the extracted source\n * input: str\n */\n try {\n r = await extractSite(input.path);\n if (r) {\n // console.log({ res: r })\n if (input.path.endsWith('.map')) {\n callStack.push('map', {\n path: r.path,\n data: '',\n mapping: r.data,\n });\n } else {\n callStack.push('source', r);\n }\n }\n } catch (e) {\n console.error(e);\n }\n } else if (type === 'source' && Transform.isString(input)) {\n /*\n * desc: raw text from the requested link\n * input: <str>\n */\n r = extractMapLink(input);\n if (r && r.length) {\n console.log('EXTRACT[source] map link', r);\n r.forEach((l) => callStack.push('link', { path: l, data: '' }));\n } else {\n callStack.push('write', { path: input.path, data: input.data });\n }\n } else if (type === 'map' && !Transform.isString(input)) {\n /*\n * desc: raw source map\n * input: json\n */\n try {\n if (!input.mapping) throw Error('Mapping missing');\n r = await extractSource(input.mapping).then((res) => {\n res?.forEach((src) => {\n callStack.push('write', src);\n });\n });\n // console.log({ map: r })\n } catch (e) {\n console.error(e);\n }\n } else if (type === 'write') {\n /*\n * desc=source and map files to write\n * input=[{\"name\": str, \"data\": json}]\n */\n Store.addToImports(input.path);\n Store.addFile(input.path, input.data);\n // if(Transform.isArray(input)){\n\n // fs.writeJSONSync(f.name, f.data)\n // });\n // }\n }\n }\n } catch (e) {\n console.error('EXTRACT[catchall]', e);\n }\n};\n\nconst run = async (callStack: Stack) => {\n while (callStack.hasMore()) {\n await extract(callStack);\n if (callStack.isEmpty()) {\n break;\n }\n }\n await Store.finalize();\n};\n\nexport const testpipeline = (files: string[], prefix: string) => {\n console.log({ files, prefix });\n return Promise.all(\n files.map((f) => {\n console.log(`pipeline started: ${f}`);\n return pipeline(f, prefix);\n })\n ).then((r) => {\n console.log('complete');\n return r;\n // console.log('finalizing package.json + index.js');\n // return Store.finalize()\n });\n // .then(() => {\n // });\n // return argz\n};\n\nimport { constants } from 'fs';\nimport { access } from 'fs/promises';\nimport { RawSourceMap } from 'source-map';\n\nasync function fileExists(path: string): Promise<boolean> {\n try {\n await access(path, constants.F_OK);\n return true;\n } catch {\n return false;\n }\n}\n\n/* EXAMPLE:\n *\n * pipeline('./maps/bitbucket/app.f606c0f20e8744e93489.js.map',\n * './build/test','map').then(() => console.log('complete'))\n */\nexport const pipeline = async (input: string, prefix = './build/src') => {\n const callStack = new Stack();\n Store.setPrefix(prefix);\n // pkg=\"test\"\n // Store.package=pkg\n if (typeof input === 'string' && input.startsWith('http')) {\n if (input.endsWith('js')) {\n callStack.push('link', { path: input, data: '' });\n } else {\n callStack.push('site', { path: input, data: '' });\n }\n } else if (await fileExists(input)) {\n callStack.push('local', { path: input, data: '' });\n } else if (isHtml(input)) {\n callStack.push('raw', { path: input, data: '' });\n } else {\n console.log('couldnt find ' + input);\n }\n await run(callStack);\n return Store.finalize();\n};\n\nconst Extractors = {\n testpipeline,\n pipeline,\n extract,\n};\n\nexport default Extractors;\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
export const extractLocal = (path) => {
|
|
3
|
+
let r = null;
|
|
4
|
+
try {
|
|
5
|
+
r = fs.readFileSync(path);
|
|
6
|
+
}
|
|
7
|
+
catch (e) {
|
|
8
|
+
console.error(e);
|
|
9
|
+
}
|
|
10
|
+
const data = r?.toString();
|
|
11
|
+
if (r && data) {
|
|
12
|
+
return { path: path, data };
|
|
13
|
+
}
|
|
14
|
+
return null;
|
|
15
|
+
// files = files.filter(f => fs.pathExistsSync(f))
|
|
16
|
+
// files = files.map(f => fs.statSync(f).isFile())
|
|
17
|
+
// const res = [];
|
|
18
|
+
// return path.map((f) => {
|
|
19
|
+
// }).filter((o) => (!!o));
|
|
20
|
+
};
|
|
21
|
+
export default extractLocal;
|
|
22
|
+
//# sourceMappingURL=local-file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-file.js","sourceRoot":"","sources":["../../../../src/lib/extractors/local-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1B,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,IAAY,EAAE,EAAE;IAC3C,IAAI,CAAC,GAAG,IAAI,CAAC;IACb,IAAI,CAAC;QACH,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACnB,CAAC;IACD,MAAM,IAAI,GAAG,CAAC,EAAE,QAAQ,EAAE,CAAC;IAC3B,IAAI,CAAC,IAAI,IAAI,EAAE,CAAC;QACd,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IAC9B,CAAC;IACD,OAAO,IAAI,CAAC;IACZ,kDAAkD;IAClD,kDAAkD;IAClD,kBAAkB;IAClB,2BAA2B;IAC3B,2BAA2B;AAC7B,CAAC,CAAC;AACF,eAAe,YAAY,CAAC","sourcesContent":["import fs from 'fs-extra';\nexport const extractLocal = (path: string) => {\n let r = null;\n try {\n r = fs.readFileSync(path);\n } catch (e) {\n console.error(e);\n }\n const data = r?.toString();\n if (r && data) {\n return { path: path, data };\n }\n return null;\n // files = files.filter(f => fs.pathExistsSync(f))\n // files = files.map(f => fs.statSync(f).isFile())\n // const res = [];\n // return path.map((f) => {\n // }).filter((o) => (!!o));\n};\nexport default extractLocal;\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import 'babel-polyfill';
|
|
2
|
+
import { RawSourceMap } from 'source-map';
|
|
3
|
+
import { StackItem } from '../pipeline/stack';
|
|
4
|
+
export declare const extractMapLink: (raw: StackItem) => string[] | undefined;
|
|
5
|
+
export declare const extractSource: (rawMap: RawSourceMap) => Promise<StackItem[]>;
|
|
6
|
+
export default extractSource;
|