main
1// Copyright 2024 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15import fs from 'node:fs'
16import path from 'node:path'
17const __dirname = path.dirname(new URL(import.meta.url).pathname)
18const root = path.resolve(__dirname, '..')
19const pkgJson = JSON.parse(
20 fs.readFileSync(path.resolve(root, 'package.json'), 'utf-8')
21)
22const deps = pkgJson.devDependencies
23
24const jsrDeps = {
25 yaml: 'jsr:@eemeli/yaml',
26 zurk: 'jsr:@webpod/zurk',
27}
28const prodDeps = new Set([
29 '@types/fs-extra',
30 '@types/minimist',
31 '@types/node',
32 '@types/which',
33 '@webpod/ingrid',
34 '@webpod/ps',
35 'chalk',
36 'create-require',
37 'depseek',
38 'envapi',
39 'fs-extra',
40 'globby',
41 'minimist',
42 'node-fetch-native',
43 'which',
44 'yaml',
45 'zurk',
46])
47
48fs.writeFileSync(
49 path.resolve(root, 'jsr.json'),
50 JSON.stringify(
51 {
52 name: '@webpod/zx',
53 version: pkgJson.version,
54 license: pkgJson.license,
55 exports: {
56 '.': './src/index.ts',
57 './core': './src/core.ts',
58 './cli': './src/cli.ts',
59 './globals': './src/globals-jsr.ts',
60 },
61 publish: {
62 include: ['src', 'README.md', 'LICENSE'],
63 exclude: ['src/globals.ts'],
64 },
65 nodeModulesDir: 'auto',
66 imports: Object.entries(deps).reduce(
67 (m, [k, v]) => {
68 if (prodDeps.has(k)) {
69 const name = jsrDeps[k] || `npm:${k}`
70 m[k] = `${name}@${v}`
71 }
72 return m
73 },
74 {
75 'zurk/spawn': `jsr:@webpod/zurk@${deps.zurk}`,
76 'zx/globals': './src/globals-jsr.ts',
77 }
78 ),
79 },
80 null,
81 2
82 )
83)
84
85console.log('jsr.json prepared for JSR')