Comments (6)
This looks already complicated =)
What about distributing package-lock.json with your script and add next line to beginning of your script:
await $`npm i`
from zx.
How about support for imports using the http protocol?
Unversioned esmodule
import yargs from 'https://unpkg.com/yargs?module';
Versioned commonjs
import yargs from 'https://unpkg.com/[email protected]';
from zx.
I thought about it, but this is a dangerous road. What about version, package-lock.json?
from zx.
I thought about it, but this is a dangerous road. What about version, package-lock.json?
The version issue may be solved as follows.
#!/usr/bin/env zx
deps({
yargs: '^17.0',
chokidar: '^3.4.3',
colorette: '1.2',
shelljs: '^0.8.4',
})
const yargs = await use('yargs')
const { hideBin } = await use('yargs/helpers')
const argv = yargs(hideBin(process.argv)).argv
if (argv.ships > 3 && argv.distance < 53.5) {
console.log('Plunder more riffiwobbles!')
} else {
console.log('Retreat from the xupptumblers!')
}
console.log(argv)
`zx.mjs` experimental basic implementation
import { join, basename, dirname } from 'path'
import os, { tmpdir } from 'os'
import { promises as fs } from 'fs'
import url from 'url'
import { v4 as uuid } from 'uuid'
import { $, cd, question, fetch, chalk, ProcessOutput } from './index.mjs'
import { version } from './version.js'
let dependencies = {}
const deps = (deps) => {
dependencies = deps
}
const use = async (packageNameOrPath) => {
let packageName = packageNameOrPath
const pathParts = packageName.split('/')
if (packageName.startsWith('@') && pathParts.length > 1) {
packageName = pathParts[0] + '/' + pathParts[1]
} else if (pathParts.length > 1) {
packageName = pathParts[0]
}
const __dirname = dirname(url.fileURLToPath(import.meta.url))
let isExist = false
try {
isExist = (
await fs.lstat(join(__dirname, 'node_modules', packageName))
).isDirectory()
} catch (e) {}
if (!isExist) {
const cwdPrev = $.cwd
$.cwd = __dirname
let packageNameWithVersion = packageName
if (dependencies[packageName]) {
packageNameWithVersion = `${packageName}@${dependencies[packageName]}`
}
await $`npm install ${packageNameWithVersion}`
$.cwd = cwdPrev
}
const p = await import(packageNameOrPath)
return p.default ?? p
}
Object.assign(global, {
$,
cd,
fetch,
question,
chalk,
fs,
os,
use,
deps,
})
....
I have no idea about package-lock.json
from zx.
I thought about it, but this is a dangerous road. What about version, package-lock.json?
I do agree with this. I think forking is probably the best thing to do if custom packages are wanted, at the end, it's a 5min change and merging back with upstream shouldn't be a problem in almost all cases.
Just as a side note: I had the same demand as I often use enquirer
for scripts. I've gone ahead and used deno instead, which actually allows for remote imports natively.
from zx.
I think this is out of the scope of the zx project. Closing.
from zx.
Related Issues (20)
- Setting stdio/err to inherit throws error HOT 1
- Typo in 8.0 release description HOT 1
- Feature request: automatically add a newline after commands that don't end their output with one HOT 4
- The type for `glob` is `any` after 8.0.0 HOT 5
- Port listening doesn't stop when using `CTRL+C` HOT 11
- Feature request: add `usePwsh` helper for PowerShell 7+ HOT 3
- Why zx instead of Python ? HOT 2
- Markdown script didn't work for CRLF file
- Is Node.js 12.17.0 supported for zx as a package ? HOT 7
- Single file executable?
- Docs: Typo in setup docs
- fetch's document link is wrong HOT 4
- bun compatibility: get rid of async_hooks.createHook call HOT 3
- cannot concatenate strings with ${} HOT 4
- Understanding `zx` roadmap and idea 🙏 HOT 6
- YAML.parseAllDocuments is no longer accessible HOT 8
- Provide better out of the box TypeScript support HOT 2
- Could not resolve "zx/globals.cjs" HOT 4
- Since 8.1.4 YAML.parseAllDocuments is not allowed from zx HOT 6
- Importing this package into CJS project triggers false-positive TypeScript error 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 zx.