-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: prepare jsr publish #989
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2e3be04
fd40a66
7701870
6d4999b
a901a51
d32aa7d
3b0501f
7c03882
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright 2024 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import fs from 'node:fs' | ||
import path from 'node:path' | ||
const __dirname = path.dirname(new URL(import.meta.url).pathname) | ||
const root = path.resolve(__dirname, '..') | ||
const pkgJson = JSON.parse( | ||
fs.readFileSync(path.resolve(root, 'package.json'), 'utf-8') | ||
) | ||
|
||
fs.writeFileSync( | ||
path.resolve(cwd, 'jsr.json'), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cwd > root There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. d1 |
||
JSON.stringify( | ||
{ | ||
name: '@zx/zx', | ||
version: pkgJson.version, | ||
exports: { | ||
'.': './src/index.ts', | ||
'./core': './src/core.ts', | ||
'./cli': './src/cli.ts', | ||
}, | ||
publish: { | ||
include: ['src', 'README.md'], | ||
}, | ||
}, | ||
null, | ||
2 | ||
) | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,19 +57,19 @@ export function printUsage() { | |
--prefix=<command> prefix all commands | ||
--postfix=<command> postfix all commands | ||
--cwd=<path> set current directory | ||
--eval=<js>, -e evaluate script | ||
--eval=<js>, -e evaluate script | ||
--ext=<.mjs> default extension | ||
--install, -i install dependencies | ||
--version, -v print current zx version | ||
--help, -h print help | ||
--repl start repl | ||
--experimental enables experimental features (deprecated) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's keep this extra line. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. d1 |
||
|
||
${chalk.italic('Full documentation:')} ${chalk.underline('https://google.github.io/zx/')} | ||
`) | ||
} | ||
|
||
export const argv = minimist(process.argv.slice(2), { | ||
export const argv: minimist.ParsedArgs = minimist(process.argv.slice(2), { | ||
string: ['shell', 'prefix', 'postfix', 'eval', 'cwd', 'ext'], | ||
boolean: [ | ||
'version', | ||
|
@@ -134,7 +134,7 @@ export async function runScript(script: string, ext = EXT) { | |
await writeAndImport(script, filepath) | ||
} | ||
|
||
export async function scriptFromStdin(ext?: string) { | ||
export async function scriptFromStdin(ext?: string): Promise<boolean> { | ||
let script = '' | ||
if (!process.stdin.isTTY) { | ||
process.stdin.setEncoding('utf8') | ||
|
@@ -178,7 +178,10 @@ export async function writeAndImport( | |
} | ||
} | ||
|
||
export async function importPath(filepath: string, origin = filepath) { | ||
export async function importPath( | ||
filepath: string, | ||
origin = filepath | ||
): Promise<void> { | ||
const ext = path.extname(filepath) | ||
const base = path.basename(filepath) | ||
const dir = path.dirname(filepath) | ||
|
@@ -206,6 +209,7 @@ export async function importPath(filepath: string, origin = filepath) { | |
await installDeps(deps, dir) | ||
} | ||
injectGlobalRequire(origin) | ||
// TODO: fix unanalyzable-dynamic-import to work correctly with jsr.io | ||
await import(url.pathToFileURL(filepath).toString()) | ||
} | ||
|
||
|
@@ -216,7 +220,7 @@ export function injectGlobalRequire(origin: string) { | |
Object.assign(globalThis, { __filename, __dirname, require }) | ||
} | ||
|
||
export function transformMarkdown(buf: Buffer) { | ||
export function transformMarkdown(buf: Buffer): string { | ||
const source = buf.toString() | ||
const output = [] | ||
let state = 'root' | ||
|
@@ -292,9 +296,9 @@ export function getVersion(): string { | |
} | ||
|
||
export function isMain( | ||
metaurl = import.meta.url, | ||
scriptpath = process.argv[1] | ||
) { | ||
metaurl: string = import.meta.url, | ||
scriptpath: string = process.argv[1] | ||
): boolean { | ||
if (metaurl.startsWith('file:')) { | ||
const modulePath = url.fileURLToPath(metaurl).replace(/\.\w+$/, '') | ||
const mainPath = fs.realpathSync(scriptpath).replace(/\.\w+$/, '') | ||
|
@@ -304,6 +308,6 @@ export function isMain( | |
return false | ||
} | ||
|
||
export function normalizeExt(ext?: string) { | ||
export function normalizeExt(ext?: string): string | undefined { | ||
return ext ? path.parse(`foo.${ext}`).ext : ext | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jsr.json
to.gitignore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahhh... its in temp. Ok, nvm