Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@
"0"
]
},
{
"type": "node",
"request": "launch",
"name": "Debug Current Test File",
"program": "${workspaceRoot}/packages/build/node_modules/.bin/_mocha",
"cwd": "${workspaceRoot}",
"autoAttachChildProcesses": true,
"args": [
"--config",
"${workspaceRoot}/packages/build/config/.mocharc.json",
"-t",
"0",
"$(node ${workspaceRoot}/packages/build/bin/get-dist-file ${file})"
],
"disableOptimisticBPs": true
},
{
"type": "node",
"request": "attach",
Expand Down
6 changes: 6 additions & 0 deletions docs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 64 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"fs-extra": "^8.1.0",
"husky": "^3.1.0",
"lerna": "^3.20.2",
"open-cli": "^5.0.0",
"typescript": "~3.7.4"
},
"scripts": {
Expand All @@ -42,7 +43,7 @@
"tsdocs": "lerna run --scope @loopback/tsdocs build:tsdocs",
"coverage:ci": "node packages/build/bin/run-nyc report --reporter=text-lcov | coveralls",
"precoverage": "npm test",
"coverage": "open coverage/index.html",
"coverage": "open-cli coverage/index.html",
"lint": "npm run prettier:check && npm run eslint && node bin/check-package-locks",
"lint:fix": "npm run eslint:fix && npm run prettier:fix",
"eslint": "node packages/build/bin/run-eslint --report-unused-disable-directives --cache .",
Expand Down
75 changes: 75 additions & 0 deletions packages/build/bin/get-dist-file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/usr/bin/env node
// Copyright IBM Corp. 2018. All Rights Reserved.
// Node module: @loopback/build
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

/*
========
This is used in the launch.json to enable you to debug a test file written in
typescript. This function attempts to convert the passed typescript file to
the best-gust output javascript file.

It walks up the filesystem from the current file, stops at package.json, and
looks in `dist`

Ideally, we could use the typescript compiler and tsconfig.json to get the
explicit output file instead of trying to guess it.

Ex:
```jsonc
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug Current Test File",
"program": "${workspaceRoot}/packages/build/node_modules/.bin/_mocha",
"cwd": "${workspaceRoot}",
"autoAttachChildProcesses": true,
"args": [
"--config",
"${workspaceRoot}/packages/build/config/.mocharc.json",
"-t",
"0",
"$(node ${workspaceRoot}/packages/build/bin/get-dist-file ${file})"
],
"disableOptimisticBPs": true
}
]
}
```

For your personal projects, you can sub directlry from loopback:
```
"$(node ${workspaceRoot}/node_modules/@loopback/build/bin/get-dist-file ${file})"
```
You still have to compile the package/project first.
========
*/

'use strict';
const path = require('path');
const fs = require('fs');

function findDistFile(filename) {
const absolutePath = path.resolve(filename);
let currentDir = path.dirname(absolutePath);
let isPackageRoot = fs.existsSync(path.resolve(currentDir, 'package.json'));
while (!isPackageRoot) {
currentDir = path.join(currentDir, '..');
isPackageRoot = fs.existsSync(path.resolve(currentDir, 'package.json'));
}
const base = path.resolve(currentDir);
const relative = path.relative(currentDir, absolutePath);
const resultPath = relative
.replace(/^src\//, 'dist/')
.replace(/\.ts$/, '.js');
return path.resolve(base, resultPath);
}

module.exports = findDistFile;
if (require.main === module) {
process.stdout.write(findDistFile(process.argv.splice(-1)[0]));
}
14 changes: 14 additions & 0 deletions packages/eslint-config/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading