Comments (6)
@alexpchin The compiled source path is determined based on the outDir
and rootDir
(or rootDirs
or baseUrl
) - which happens here. So maybe there's something that you can tweak there to make it find the right path?
from core.
Hi @mdonnalley the reason I'm having the issue is that I'm using pnpm and I'm requiring another package without setting rootDir, just setting baseUrl. This means each package is added to the lib folder.
I could possibly look at tweaking this by looking at typescript references (I believe) but this may/may not work for us.
Is there no way to supply an alternative config just for use with ts-node as it won't be looking in the lib folder? If I change to /src/commands everything works with ts-node which obviously breaks then when using run?
from core.
Let me make sure I understand:
You want to use ./src/commands
when running bin/dev.js
and you want to use ./dist/bunk-cli/src/commands
when running bin/run.js
? And the reason is that tsPath
can't correctly resolve ./dist/bunk-cli/src/commands
back to ./src/commands
?
Is there no way to supply an alternative config just for use with ts-node as it won't be looking in the lib folder?
No, I can't think of anything that would allow you to do this without some code changes.
Probably the easiest code change that could be made is to have an env var that overrides any reference to this.pjson.oclif.commands
in src/config/plugin.ts
Usage would be something like:
OCLIF_COMMANDS_OVERRIDE=./src/commands bin/dev.js
Would be happy to accept a PR if you would like to make that change.
If you don't want that, I have a couple of ideas you could try on your side:
- Precompile code prior to using
bin/dev.js
(I realize that this defeats the purpose ofbin/dev.js
) - Have
bin/dev.js
modify the package.json prior to executing and then restoring it after execution completes
Neither of those are great but you could give them a try.
from core.
@mdonnalley That's exactly the issue. A couple of ideas, could we enable passing of options to execute via loadOptions? Or specify a .oclifrc file?
this.OCLIF_CONFIG = process.env.OCLIFRC ?? 'package.json';
this.pjson = await readJson(join(root, this.OCLIF_CONFIG));
It might allow for more configuration without having to set separate options as environment variables?
Basically, the problem is that ts-node and tsc output files differently when not using typescript's rootDir in a monorepo (TypeScript determines one parent folder containing all your source files. This folder is set as [rootDir] in tsconfig.json or calculated automatically by the compiler).
So I think it would be useful to be able to set:
- .oclifrc.dev.json for dev (ts-node)
- .oclifrc.json for both build script and run (tsc).
Another idea, you could also possibly add the bunk-cli/src as a relativeOutDir
option? I.e. when using ts-node and an relativeOutDir
option is provided, remove it from the commands and hooks in package.json? To make /dist/bunk-cli/src/commands
become /dist/commands
? /outDir/(relativeOutDir?)/commands
from core.
I don't think that we're likely to add support for an rc file. As it is, we're just too dependent on the package.json (for things other than the oclif
section) and I don't want to add the complexity of another configuration source.
For an unrelated reason, I added a pjson
option to the LoadOptions
that can be passed to execute
in #945
You'd have to read the package.json
, modify oclif.commands
and then pass that into execute. Something like this:
const pjson = JSON.parse(await readFile('package.json', 'utf8'))
pjson.oclif.commands = './src/commands'
await execute({
loadOptions: {
pjson,
root: __dirname,
},
})
Would that work for you?
If you want, you can test it out yourself using @oclif/[email protected]
from core.
Hi @mdonnalley Thanks, that works nicely! Amazing. Just for reference this is my full dev.js
#!/usr/bin/env -S node --import ts-node/esm --no-warnings=ExperimentalWarning
// eslint-disable-next-line unicorn/prefer-top-level-await
(async () => {
const tsConfig = await import('../tsconfig.json');
const tsConfigPaths = await import('tsconfig-paths');
tsConfigPaths.register({
baseUrl: './',
paths: tsConfig.compilerOptions.paths,
});
/**
* Due to typescript building into dist in a non-flat way,
* i.e. tsc is assuming the rootDir to be the root of the momonrepo
* because we're requiring files from other packages, i.e. bunk-models
* then we have to load a different location for the oclif commands
* to work when loading with ts-node which is on-the-fly.
*/
const { readFile } = await import('fs/promises');
const path = await import('path');
const pjsonPath = path.join(__dirname, '..', 'package.json');
const data = await readFile(pjsonPath, 'utf8');
const pjson = JSON.parse(data);
const commandsPath = './src/commands';
const hooksPath = './src/hooks/custom/init-config';
pjson.oclif = {
bin: 'bunk-cli',
commands: commandsPath,
hooks: {
'init-config': hooksPath,
},
};
const { execute, settings } = await import('@oclif/core');
// settings.performanceEnabled = true;
const root = path.join(__dirname, '..');
await execute({
development: true,
loadOptions: {
pjson,
root,
},
});
})();
from core.
Related Issues (20)
- topicSeparator space generates wrong message when used alongside usage HOT 1
- Upgrading to a version after 3.20.0 causes issues with hooks HOT 3
- (help): show arg/flag options if user didn't provide any HOT 1
- Command summary displays as topic summary when nested below topic without summary. HOT 1
- Unable to run dev.js outside of the project folder
- BaseCommand Documentation HOT 3
- Native support for .env files HOT 1
- bun with oclif not catching unhandled exceptions
- [BUG]The issue of ux.prompt handling special characters. HOT 3
- Can't run development mode with bun HOT 2
- RangeError on ux.table when column starts with emoji HOT 1
- ux.Table: Incorrect parsing of double quotes when exporting to CSV HOT 3
- ux.table `maxWidth` column option HOT 2
- CliUx.ux.prompt text truncation HOT 3
- Build failure with `exactOptionalPropertyTypes` enabled HOT 5
- [Feature request] Alias a single flag to a set of multiple flags HOT 1
- Getting MaxListenersExceededWarning: Possible EventEmitter memory leak detected. after updating to latest version of oclif HOT 2
- Error bundling @oclif/core into my project HOT 15
- UX tables get displayed along with json output on usage of --json flag HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from core.