@ryanatkn/gro 0.113.0 → 0.114.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,12 +14,12 @@ export declare const Args: z.ZodObject<{
14
14
  changelog: z.ZodDefault<z.ZodString>;
15
15
  install: z.ZodDefault<z.ZodBoolean>;
16
16
  'no-install': z.ZodDefault<z.ZodBoolean>;
17
- origin: z.ZodDefault<z.ZodString>;
17
+ origin: z.ZodDefault<z.ZodBranded<z.ZodString, "Git_Origin">>;
18
18
  }, "strict", z.ZodTypeAny, {
19
19
  _: string[];
20
20
  dir: string;
21
21
  install: boolean;
22
- origin: string;
22
+ origin: string & z.BRAND<"Git_Origin">;
23
23
  minor: boolean;
24
24
  major: boolean;
25
25
  changelog: string;
@@ -9,6 +9,7 @@ import { exists } from './fs.js';
9
9
  import { load_package_json } from './package_json.js';
10
10
  import { find_cli, spawn_cli } from './cli.js';
11
11
  import { Git_Origin, git_push_to_create } from './git.js';
12
+ import { has_sveltekit_library } from './gro_plugin_sveltekit_library.js';
12
13
  const RESTRICTED_ACCESS = 'restricted';
13
14
  const PUBLIC_ACCESS = 'public';
14
15
  const CHANGESET_DIR = '.changeset';
@@ -60,9 +61,12 @@ export const task = {
60
61
  if (!(await find_cli('changeset'))) {
61
62
  throw new Task_Error('changeset command not found: install @changesets/cli locally or globally');
62
63
  }
64
+ const package_json = await load_package_json();
65
+ if (!(await has_sveltekit_library(package_json))) {
66
+ throw new Task_Error('no SvelteKit library detected');
67
+ }
63
68
  const path = join(dir, 'config.json');
64
69
  const inited = await exists(path);
65
- const package_json = await load_package_json();
66
70
  if (!inited) {
67
71
  await spawn_cli('changeset', ['init']);
68
72
  const access = access_arg ?? package_json.private ? RESTRICTED_ACCESS : PUBLIC_ACCESS;
@@ -6,14 +6,14 @@ export declare const Args: z.ZodObject<{
6
6
  sveltekit: z.ZodDefault<z.ZodBoolean>;
7
7
  nodemodules: z.ZodDefault<z.ZodBoolean>;
8
8
  git: z.ZodDefault<z.ZodBoolean>;
9
- git_origin: z.ZodDefault<z.ZodString>;
9
+ git_origin: z.ZodDefault<z.ZodBranded<z.ZodString, "Git_Origin">>;
10
10
  }, "strict", z.ZodTypeAny, {
11
11
  build_dev: boolean;
12
12
  build_dist: boolean;
13
13
  sveltekit: boolean;
14
14
  nodemodules: boolean;
15
15
  git: boolean;
16
- git_origin: string;
16
+ git_origin: string & z.BRAND<"Git_Origin">;
17
17
  }, {
18
18
  build_dev?: boolean | undefined;
19
19
  build_dist?: boolean | undefined;
@@ -1,6 +1,7 @@
1
1
  import { spawn } from '@ryanatkn/belt/process.js';
2
2
  import { z } from 'zod';
3
3
  import { clean_fs } from './clean_fs.js';
4
+ import { Git_Origin } from './git.js';
4
5
  export const Args = z
5
6
  .object({
6
7
  build_dev: z.boolean({ description: 'delete the Gro build dev directory' }).default(false),
@@ -14,11 +15,7 @@ export const Args = z
14
15
  description: 'run "git remote prune" to delete local branches referencing nonexistent remote branches',
15
16
  })
16
17
  .default(false),
17
- git_origin: z
18
- .string({
19
- description: 'the origin to "git remote prune"',
20
- })
21
- .default('origin'),
18
+ git_origin: Git_Origin.describe('the origin to "git remote prune"').default('origin'),
22
19
  })
23
20
  .strict();
24
21
  export const task = {
@@ -2,10 +2,13 @@ import { z } from 'zod';
2
2
  import type { Task } from './task.js';
3
3
  export declare const Args: z.ZodObject<{
4
4
  _: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
5
+ origin: z.ZodDefault<z.ZodBranded<z.ZodString, "Git_Origin">>;
5
6
  }, "strict", z.ZodTypeAny, {
6
7
  _: string[];
8
+ origin: string & z.BRAND<"Git_Origin">;
7
9
  }, {
8
10
  _?: string[] | undefined;
11
+ origin?: string | undefined;
9
12
  }>;
10
13
  export type Args = z.infer<typeof Args>;
11
14
  export declare const task: Task<Args>;
@@ -1,6 +1,6 @@
1
1
  import { spawn } from '@ryanatkn/belt/process.js';
2
2
  import { z } from 'zod';
3
- import { git_current_branch_name } from './git.js';
3
+ import { Git_Origin, git_current_branch_name, git_push } from './git.js';
4
4
  export const Args = z
5
5
  .object({
6
6
  _: z
@@ -8,15 +8,16 @@ export const Args = z
8
8
  description: 'the git commit message, the same as git commit -m or --message',
9
9
  })
10
10
  .default([]),
11
+ origin: Git_Origin.describe('git origin to commit to').default('origin'),
11
12
  })
12
13
  .strict();
13
14
  export const task = {
14
15
  summary: 'commit and push to a new branch',
15
16
  Args,
16
17
  run: async ({ args }) => {
17
- const { _: [message], } = args;
18
+ const { _: [message], origin, } = args;
18
19
  const branch = await git_current_branch_name();
19
20
  await spawn('git', ['commit', '-a', '-m', message]);
20
- await spawn(`git push -u origin ${branch}`, [], { shell: true });
21
+ await git_push(origin, branch, undefined, true);
21
22
  },
22
23
  };
@@ -1,9 +1,9 @@
1
1
  import { z } from 'zod';
2
2
  import { type Task } from './task.js';
3
3
  export declare const Args: z.ZodObject<{
4
- source: z.ZodDefault<z.ZodString>;
5
- target: z.ZodDefault<z.ZodString>;
6
- origin: z.ZodDefault<z.ZodString>;
4
+ source: z.ZodDefault<z.ZodBranded<z.ZodString, "Git_Branch">>;
5
+ target: z.ZodDefault<z.ZodBranded<z.ZodString, "Git_Branch">>;
6
+ origin: z.ZodDefault<z.ZodBranded<z.ZodString, "Git_Origin">>;
7
7
  deploy_dir: z.ZodDefault<z.ZodString>;
8
8
  build_dir: z.ZodDefault<z.ZodString>;
9
9
  dry: z.ZodDefault<z.ZodBoolean>;
@@ -16,12 +16,12 @@ export declare const Args: z.ZodObject<{
16
16
  'no-build': z.ZodDefault<z.ZodBoolean>;
17
17
  }, "strict", z.ZodTypeAny, {
18
18
  build: boolean;
19
- target: string;
19
+ target: string & z.BRAND<"Git_Branch">;
20
20
  install: boolean;
21
- origin: string;
21
+ origin: string & z.BRAND<"Git_Origin">;
22
22
  reset: boolean;
23
23
  'no-install': boolean;
24
- source: string;
24
+ source: string & z.BRAND<"Git_Branch">;
25
25
  deploy_dir: string;
26
26
  build_dir: string;
27
27
  dry: boolean;
@@ -120,7 +120,7 @@ export const task = {
120
120
  // It may not exist, or it may have been deleted after failing to sync above.
121
121
  if (!(await exists(resolved_deploy_dir))) {
122
122
  const local_deploy_branch_exists = await git_local_branch_exists(target);
123
- await git_fetch(origin, '+' + target + ':' + target); // fetch+merge and allow non-fastforward updates with the +
123
+ await git_fetch(origin, ('+' + target + ':' + target)); // fetch+merge and allow non-fastforward updates with the +
124
124
  await git_clone_locally(origin, target, cwd, resolved_deploy_dir);
125
125
  // Clean up if we created the target branch in the cwd
126
126
  if (!local_deploy_branch_exists) {
@@ -22,13 +22,13 @@ export const gen = async ({ origin_id }) => {
22
22
  const output_file_name = to_output_file_name(origin_base);
23
23
  // TODO this is GitHub-specific
24
24
  const root_link = `[${root_path}](/../..)`;
25
- const docFiles = await search_fs(origin_dir);
26
- const docPaths = [];
27
- for (const path of docFiles.keys()) {
25
+ const doc_files = await search_fs(origin_dir);
26
+ const doc_paths = [];
27
+ for (const path of doc_files.keys()) {
28
28
  if (path === output_file_name || !path.endsWith('.md')) {
29
29
  continue;
30
30
  }
31
- docPaths.push(path);
31
+ doc_paths.push(path);
32
32
  }
33
33
  // TODO do we want to use absolute paths instead of relative paths,
34
34
  // because GitHub works with them and it simplifies the code?
@@ -45,7 +45,7 @@ export const gen = async ({ origin_id }) => {
45
45
 
46
46
  ${breadcrumbs}
47
47
 
48
- ${docPaths.reduce((docList, doc) => docList + `- [${basename(doc, '.md')}](${doc})\n`, '')}
48
+ ${doc_paths.reduce((docList, doc) => docList + `- [${basename(doc, '.md')}](${doc})\n`, '')}
49
49
  ${breadcrumbs}
50
50
 
51
51
  > <sub>generated by [${origin_base}](${origin_base})</sub>
@@ -7,7 +7,7 @@
7
7
  - [deploy](deploy.md)
8
8
  - [dev](dev.md)
9
9
  - [gen](gen.md)
10
- - [gro_plugin_sveltekit_frontend](gro_plugin_sveltekit_frontend.md)
10
+ - [gro_plugin_sveltekit_app](gro_plugin_sveltekit_app.md)
11
11
  - [package_json](package_json.md)
12
12
  - [plugin](plugin.md)
13
13
  - [publish](publish.md)
@@ -15,7 +15,7 @@ const config: Gro_ConfigCreator = async (cfg) => {
15
15
  // host_target?: Host_Target;
16
16
  // well_known_package_json?: boolean | Map_Package_Json;
17
17
  // well_known_src_json?: boolean | Map_Src_Json;
18
- // filter_well_known_src?: (source: string, destination: string) => boolean | Promise<boolean>;
18
+ // well_known_src?: boolean | Copy_File_Filter;
19
19
  }),
20
20
  ];
21
21
  return cfg;
@@ -26,9 +26,19 @@ export default config;
26
26
  // src/lib/gro_plugin_sveltekit_app.ts
27
27
  export type Host_Target = 'github_pages' | 'static' | 'node';
28
28
 
29
+ export interface Copy_File_Filter {
30
+ (file_path: string): boolean | Promise<boolean>;
31
+ }
32
+
33
+ // src/lib/package_json.ts
29
34
  export interface Map_Package_Json {
30
35
  (package_json: Package_Json): Package_Json | null | Promise<Package_Json | null>;
31
36
  }
37
+
38
+ // src/lib/src_json.ts
39
+ export interface Map_Src_Json {
40
+ (src_json: Src_Json): Src_Json | null | Promise<Src_Json | null>;
41
+ }
32
42
  ```
33
43
 
34
44
  ## `host_target`
@@ -92,6 +102,12 @@ The `.well-known/src.json` file contains more details about
92
102
  the `package.json`'s `exports`, like exported identifier names and types.
93
103
  It maps each export to a source file in `.well-known/src/`.
94
104
 
95
- The contents of your `src/` directory are copied to `.well-known/src/`
96
- using the same filter as `exports` in `package.json` by default,
97
- and this can be customized with `filter_well_known_src`.
105
+ ## `well_known_src`
106
+
107
+ The contents of your `src/` directory can be included in the output
108
+ if you want your app's source code to be available the same as the built files.
109
+ This is disabled by default.
110
+ If `well_known_src` is truthy,
111
+ the plugin copies `src/` to `static/.well-known/src/` during `vite build`.
112
+ Passing `true` uses the same filter as `exports` in `package.json` by default,
113
+ and it also accepts a custom filter function.
@@ -12,18 +12,21 @@ behavior designed for public open source projects:
12
12
  copies `package.json` from your project root to your
13
13
  SvelteKit static directory at `.well-known/package.json` during `vite build`,
14
14
  mapping it with the optional
15
- [`well_known_package_json` option](./gro_plugin_sveltekit_app.md#well_known_package_json)
15
+ [`well_known_package_json` option](./gro_plugin_sveltekit_app.md#well_known_package_json).
16
16
  - `gro_plugin_sveltekit_app` outputs `.well-known/src.json`
17
17
  using the `exports` property of `package.json` during `vite build`,
18
18
  containing additional information about the source modules,
19
19
  mapping it with the optional
20
- [`well_known_src_json` option](./gro_plugin_sveltekit_app.md#well_known_src_json)
21
- - `gro_plugin_sveltekit_app` outputs `.well-known/src/` by
22
- copying over `src/` filtered by `filter_well_known_src` during `vite build` -
23
- this is costly (usually more than doubling the final output size
20
+ [`well_known_src_json` option](./gro_plugin_sveltekit_app.md#well_known_src_json).
21
+ - If you opt in with `well_known_src`,
22
+ `gro_plugin_sveltekit_app` outputs `.well-known/src/` by
23
+ copying over `src/` during `vite build`, filtered by `well_known_src` if it's a function.
24
+ This is costly (usually more than doubling the final output size
24
25
  of the code files in bytes, not counting images and such),
25
- and it slows the build because it copies your entire source tree (sorry to hard drives),
26
- but the UX is not affected
26
+ it slows the build because it copies your entire source tree (sorry to hard drives),
27
+ and it exposes your source code the same as the built files.
27
28
 
28
- > ⚠️ Setting `"public": true` in `package.json` exposes your source code at your deployed endpoint!
29
- > If that's the public web, that means your source code is public.
29
+ > ⚠️ Setting `"public": true` in `package.json` exposes your `package.json`
30
+ > and `src.json` metadata with your other built files by default!
31
+ > Further opting in with `well_known_src` exposes your actual source files.
32
+ > If your built files are public, that means these additional files are also public.
package/dist/git.d.ts CHANGED
@@ -1,23 +1,22 @@
1
1
  /// <reference types="node" />
2
- import type { Flavored } from '@ryanatkn/belt/types.js';
3
2
  import type { SpawnOptions } from 'child_process';
4
3
  import { z } from 'zod';
5
- export declare const Git_Origin: z.ZodString;
6
- export type Git_Origin = Flavored<z.infer<typeof Git_Origin>, 'Git_Origin'>;
7
- export declare const Git_Branch: z.ZodString;
8
- export type Git_Branch = Flavored<z.infer<typeof Git_Branch>, 'Git_Branch'>;
4
+ export declare const Git_Origin: z.ZodBranded<z.ZodString, "Git_Origin">;
5
+ export type Git_Origin = z.infer<typeof Git_Origin>;
6
+ export declare const Git_Branch: z.ZodBranded<z.ZodString, "Git_Branch">;
7
+ export type Git_Branch = z.infer<typeof Git_Branch>;
9
8
  /**
10
9
  * Returns the current git branch name or throws if something goes wrong.
11
10
  */
12
- export declare const git_current_branch_name: (options?: SpawnOptions) => Promise<string>;
11
+ export declare const git_current_branch_name: (options?: SpawnOptions) => Promise<Git_Branch>;
13
12
  /**
14
13
  * @returns a boolean indicating if the remote git branch exists
15
14
  */
16
- export declare const git_remote_branch_exists: (origin?: Flavored<string, "Git_Origin">, branch?: any, options?: SpawnOptions) => Promise<boolean>;
15
+ export declare const git_remote_branch_exists: (origin?: Git_Origin, branch?: Git_Branch, options?: SpawnOptions) => Promise<boolean>;
17
16
  /**
18
17
  * @returns a boolean indicating if the local git branch exists
19
18
  */
20
- export declare const git_local_branch_exists: (branch: Flavored<string, "Git_Branch">, options?: SpawnOptions) => Promise<boolean>;
19
+ export declare const git_local_branch_exists: (branch: Git_Branch, options?: SpawnOptions) => Promise<boolean>;
21
20
  /**
22
21
  * TODO make this return an enum and separate the text into a different function
23
22
  * @returns an error message if the git workspace has any unstaged or uncommitted changes, or `null` if it's clean
@@ -26,36 +25,36 @@ export declare const git_check_clean_workspace: (options?: SpawnOptions) => Prom
26
25
  /**
27
26
  * Calls `git fetch` and throws if anything goes wrong.
28
27
  */
29
- export declare const git_fetch: (origin?: Flavored<string, "Git_Origin">, branch?: any, options?: SpawnOptions) => Promise<void>;
28
+ export declare const git_fetch: (origin?: Git_Origin, branch?: Git_Branch, options?: SpawnOptions) => Promise<void>;
30
29
  /**
31
30
  * Calls `git checkout` and throws if anything goes wrong.
32
31
  * @returns the previous branch name, if it changed
33
32
  */
34
- export declare const git_checkout: (branch: Flavored<string, "Git_Branch">, options?: SpawnOptions) => Promise<Git_Branch | null>;
33
+ export declare const git_checkout: (branch: Git_Branch, options?: SpawnOptions) => Promise<Git_Branch | null>;
35
34
  /**
36
35
  * Calls `git pull` and throws if anything goes wrong.
37
36
  */
38
- export declare const git_pull: (origin?: Flavored<string, "Git_Origin">, branch?: any, options?: SpawnOptions) => Promise<void>;
37
+ export declare const git_pull: (origin?: Git_Origin, branch?: Git_Branch, options?: SpawnOptions) => Promise<void>;
39
38
  /**
40
39
  * Calls `git push` and throws if anything goes wrong.
41
40
  */
42
- export declare const git_push: (origin: Flavored<string, "Git_Origin">, branch: Flavored<string, "Git_Branch">, options?: SpawnOptions) => Promise<void>;
41
+ export declare const git_push: (origin: Git_Origin, branch: Git_Branch, options?: SpawnOptions, set_upstream?: boolean) => Promise<void>;
43
42
  /**
44
43
  * Calls `git push` and throws if anything goes wrong.
45
44
  */
46
- export declare const git_push_to_create: (origin?: Flavored<string, "Git_Origin">, branch?: any, options?: SpawnOptions) => Promise<void>;
45
+ export declare const git_push_to_create: (origin?: Git_Origin, branch?: Git_Branch, options?: SpawnOptions) => Promise<void>;
47
46
  /**
48
47
  * Deletes a branch locally and throws if anything goes wrong.
49
48
  */
50
- export declare const git_delete_local_branch: (branch: Flavored<string, "Git_Branch">, options?: SpawnOptions) => Promise<void>;
49
+ export declare const git_delete_local_branch: (branch: Git_Branch, options?: SpawnOptions) => Promise<void>;
51
50
  /**
52
51
  * Deletes a branch remotely and throws if anything goes wrong.
53
52
  */
54
- export declare const git_delete_remote_branch: (origin: Flavored<string, "Git_Origin">, branch: Flavored<string, "Git_Branch">, options?: SpawnOptions) => Promise<void>;
53
+ export declare const git_delete_remote_branch: (origin: Git_Origin, branch: Git_Branch, options?: SpawnOptions) => Promise<void>;
55
54
  /**
56
55
  * Resets the `target` branch back to its first commit both locally and remotely.
57
56
  */
58
- export declare const git_reset_branch_to_first_commit: (origin: Flavored<string, "Git_Origin">, branch: Flavored<string, "Git_Branch">, options?: SpawnOptions) => Promise<void>;
57
+ export declare const git_reset_branch_to_first_commit: (origin: Git_Origin, branch: Git_Branch, options?: SpawnOptions) => Promise<void>;
59
58
  /**
60
59
  * Returns the branch's latest commit hash or throws if something goes wrong.
61
60
  */
@@ -73,4 +72,4 @@ export declare const git_check_setting_pull_rebase: (options?: SpawnOptions) =>
73
72
  /**
74
73
  * Clones a branch locally to another directory and updates the origin to match the source.
75
74
  */
76
- export declare const git_clone_locally: (origin: Flavored<string, "Git_Origin">, branch: Flavored<string, "Git_Branch">, source_dir: string, target_dir: string, options?: SpawnOptions) => Promise<void>;
75
+ export declare const git_clone_locally: (origin: Git_Origin, branch: Git_Branch, source_dir: string, target_dir: string, options?: SpawnOptions) => Promise<void>;
package/dist/git.js CHANGED
@@ -3,8 +3,8 @@ import { z } from 'zod';
3
3
  import { exists } from './fs.js';
4
4
  import { to_file_path } from './path.js';
5
5
  // TODO maybe extract to `util-git`
6
- export const Git_Origin = z.string();
7
- export const Git_Branch = z.string();
6
+ export const Git_Origin = z.string().brand('Git_Origin');
7
+ export const Git_Branch = z.string().brand('Git_Branch');
8
8
  /**
9
9
  * Returns the current git branch name or throws if something goes wrong.
10
10
  */
@@ -105,9 +105,12 @@ export const git_pull = async (origin = 'origin', branch, options) => {
105
105
  /**
106
106
  * Calls `git push` and throws if anything goes wrong.
107
107
  */
108
- export const git_push = async (origin, branch, options) => {
108
+ export const git_push = async (origin, branch, options, set_upstream = false) => {
109
109
  const final_branch = branch ?? (await git_current_branch_name(options));
110
- const result = await spawn('git', ['push', origin, final_branch], options);
110
+ const args = ['push', origin, final_branch];
111
+ if (set_upstream)
112
+ args.push('-u');
113
+ const result = await spawn('git', args, options);
111
114
  if (!result.ok) {
112
115
  throw Error(`git_push failed for branch '${final_branch}' with code ${result.code}`);
113
116
  }
@@ -19,9 +19,13 @@ export interface Options {
19
19
  */
20
20
  well_known_src_json?: boolean | Map_Src_Json;
21
21
  /**
22
- * Filter what's copied from `src/` to `.well-known/src/`.
22
+ * If truthy, copies `src/` to `/.well-known/src/` to the static output.
23
+ * Pass a function to customize which files get copied.
23
24
  */
24
- filter_well_known_src?: (source: string, destination: string) => boolean | Promise<boolean>;
25
+ well_known_src?: boolean | Copy_File_Filter;
25
26
  }
26
27
  export type Host_Target = 'github_pages' | 'static' | 'node';
27
- export declare const gro_plugin_sveltekit_app: ({ host_target, well_known_package_json, well_known_src_json, filter_well_known_src, }?: Options) => Plugin<Plugin_Context>;
28
+ export interface Copy_File_Filter {
29
+ (file_path: string): boolean | Promise<boolean>;
30
+ }
31
+ export declare const gro_plugin_sveltekit_app: ({ host_target, well_known_package_json, well_known_src_json, well_known_src, }?: Options) => Plugin<Plugin_Context>;
@@ -11,7 +11,7 @@ import { serialize_src_json, create_src_json } from './src_json.js';
11
11
  import { DEFAULT_EXPORTS_EXCLUDER } from './config.js';
12
12
  import { SVELTEKIT_CONFIG_FILENAME } from './paths.js';
13
13
  export const has_sveltekit_app = () => exists(SVELTEKIT_CONFIG_FILENAME);
14
- export const gro_plugin_sveltekit_app = ({ host_target = 'github_pages', well_known_package_json, well_known_src_json, filter_well_known_src = (source) => !DEFAULT_EXPORTS_EXCLUDER.test(source), } = {}) => {
14
+ export const gro_plugin_sveltekit_app = ({ host_target = 'github_pages', well_known_package_json, well_known_src_json, well_known_src, } = {}) => {
15
15
  let sveltekit_process = null;
16
16
  return {
17
17
  name: 'gro_plugin_sveltekit_app',
@@ -65,8 +65,10 @@ export const gro_plugin_sveltekit_app = ({ host_target = 'github_pages', well_kn
65
65
  serialized_src_json
66
66
  ? await create_temporarily(join(assets_path, '.well-known/src.json'), serialized_src_json)
67
67
  : null,
68
- serialized_src_json
69
- ? await copy_temporarily('src', assets_path, '.well-known', filter_well_known_src)
68
+ serialized_src_json && well_known_src
69
+ ? await copy_temporarily('src', assets_path, '.well-known', well_known_src === true
70
+ ? (file_path) => !DEFAULT_EXPORTS_EXCLUDER.test(file_path)
71
+ : well_known_src)
70
72
  : null,
71
73
  /**
72
74
  * GitHub pages processes everything with Jekyll by default,
package/dist/package.d.ts CHANGED
@@ -95,6 +95,7 @@ export declare const package_json: {
95
95
  default: string;
96
96
  types: string;
97
97
  };
98
+ './package.json': string;
98
99
  './args.js': {
99
100
  default: string;
100
101
  types: string;
@@ -416,6 +417,10 @@ export declare const src_json: {
416
417
  kind: string;
417
418
  }[];
418
419
  };
420
+ './package.json': {
421
+ path: string;
422
+ declarations: never[];
423
+ };
419
424
  './args.js': {
420
425
  path: string;
421
426
  declarations: {
package/dist/package.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // generated by src/lib/package.gen.ts
2
2
  export const package_json = {
3
3
  name: '@ryanatkn/gro',
4
- version: '0.113.0',
4
+ version: '0.114.0',
5
5
  description: 'task runner and toolkit extending SvelteKit',
6
6
  icon: '🌰',
7
7
  public: true,
@@ -78,6 +78,7 @@ export const package_json = {
78
78
  },
79
79
  exports: {
80
80
  '.': { default: './dist/index.js', types: './dist/index.d.ts' },
81
+ './package.json': './package.json',
81
82
  './args.js': { default: './dist/args.js', types: './dist/args.d.ts' },
82
83
  './build.task.js': { default: './dist/build.task.js', types: './dist/build.task.d.ts' },
83
84
  './changelog.js': { default: './dist/changelog.js', types: './dist/changelog.d.ts' },
@@ -234,7 +235,7 @@ export const package_json = {
234
235
  };
235
236
  export const src_json = {
236
237
  name: '@ryanatkn/gro',
237
- version: '0.113.0',
238
+ version: '0.114.0',
238
239
  modules: {
239
240
  '.': {
240
241
  path: 'index.ts',
@@ -250,6 +251,7 @@ export const src_json = {
250
251
  { name: 'Task_Error', kind: 'class' },
251
252
  ],
252
253
  },
254
+ './package.json': { path: 'package.json', declarations: [] },
253
255
  './args.js': {
254
256
  path: 'args.ts',
255
257
  declarations: [
@@ -525,6 +527,7 @@ export const src_json = {
525
527
  { name: 'has_sveltekit_app', kind: 'function' },
526
528
  { name: 'Options', kind: 'type' },
527
529
  { name: 'Host_Target', kind: 'type' },
530
+ { name: 'Copy_File_Filter', kind: 'type' },
528
531
  { name: 'gro_plugin_sveltekit_app', kind: 'function' },
529
532
  ],
530
533
  },
@@ -39,7 +39,7 @@ export declare const Package_Json_Funding: z.ZodUnion<[z.ZodString, z.ZodObject<
39
39
  url: z.ZodString;
40
40
  }, z.ZodTypeAny, "passthrough">>]>;
41
41
  export type Package_Json_Funding = z.infer<typeof Package_Json_Funding>;
42
- export declare const Package_Json_Exports: z.ZodRecord<z.ZodString, z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>>;
42
+ export declare const Package_Json_Exports: z.ZodRecord<z.ZodString, z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>>;
43
43
  export type Package_Json_Exports = z.infer<typeof Package_Json_Exports>;
44
44
  /**
45
45
  * @see https://docs.npmjs.com/cli/v10/configuring-npm/package-json
@@ -125,7 +125,7 @@ export declare const Package_Json: z.ZodIntersection<z.ZodRecord<z.ZodString, z.
125
125
  scripts: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
126
126
  bin: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
127
127
  files: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
128
- exports: z.ZodOptional<z.ZodEffects<z.ZodRecord<z.ZodString, z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>>, any, Record<string, Record<string, string> | undefined>>>;
128
+ exports: z.ZodOptional<z.ZodEffects<z.ZodRecord<z.ZodString, z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>>, any, Record<string, string | Record<string, string> | undefined>>>;
129
129
  dependencies: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
130
130
  devDependencies: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
131
131
  peerDependencies: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
@@ -215,7 +215,7 @@ export declare const Package_Json: z.ZodIntersection<z.ZodRecord<z.ZodString, z.
215
215
  scripts: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
216
216
  bin: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
217
217
  files: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
218
- exports: z.ZodOptional<z.ZodEffects<z.ZodRecord<z.ZodString, z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>>, any, Record<string, Record<string, string> | undefined>>>;
218
+ exports: z.ZodOptional<z.ZodEffects<z.ZodRecord<z.ZodString, z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>>, any, Record<string, string | Record<string, string> | undefined>>>;
219
219
  dependencies: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
220
220
  devDependencies: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
221
221
  peerDependencies: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
@@ -305,7 +305,7 @@ export declare const Package_Json: z.ZodIntersection<z.ZodRecord<z.ZodString, z.
305
305
  scripts: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
306
306
  bin: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
307
307
  files: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
308
- exports: z.ZodOptional<z.ZodEffects<z.ZodRecord<z.ZodString, z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>>, any, Record<string, Record<string, string> | undefined>>>;
308
+ exports: z.ZodOptional<z.ZodEffects<z.ZodRecord<z.ZodString, z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>>, any, Record<string, string | Record<string, string> | undefined>>>;
309
309
  dependencies: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
310
310
  devDependencies: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
311
311
  peerDependencies: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
@@ -42,7 +42,7 @@ export const Package_Json_Funding = z.union([
42
42
  })
43
43
  .passthrough(),
44
44
  ]);
45
- export const Package_Json_Exports = z.record(z.record(z.string()).optional());
45
+ export const Package_Json_Exports = z.record(z.union([z.string(), z.record(z.string())]).optional());
46
46
  /**
47
47
  * @see https://docs.npmjs.com/cli/v10/configuring-npm/package-json
48
48
  */
@@ -149,13 +149,22 @@ export const update_package_json = async (dir = paths.root, update, write = true
149
149
  await write_package_json(updated_contents);
150
150
  return { package_json: updated, changed: true };
151
151
  };
152
+ const is_index = (path) => path === 'index.ts' || path === 'index.js';
152
153
  export const to_package_exports = (paths) => {
153
154
  const sorted = paths
154
155
  .slice()
155
- .sort((a, b) => (a === 'index.ts' ? -1 : b === 'index.ts' ? 1 : a.localeCompare(b)));
156
+ .sort((a, b) => (is_index(a) ? -1 : is_index(b) ? 1 : a.localeCompare(b)));
157
+ // Add the package.json after the index, if one exists.
158
+ // Including the `./` here ensures we don't conflict with any potential `$lib/package.json`.
159
+ const final_sorted = is_index(sorted[0])
160
+ ? [sorted[0]].concat('./package.json', sorted.slice(1))
161
+ : ['./package.json'].concat(sorted);
156
162
  const exports = {};
157
- for (const path of sorted) {
158
- if (path.endsWith('.json.d.ts')) {
163
+ for (const path of final_sorted) {
164
+ if (path === './package.json') {
165
+ exports['./package.json'] = './package.json';
166
+ }
167
+ else if (path.endsWith('.json.d.ts')) {
159
168
  const json_path = path.substring(0, path.length - 5);
160
169
  exports['./' + json_path] = {
161
170
  default: IMPORT_PREFIX + json_path, // assuming a matching json file
@@ -164,14 +173,14 @@ export const to_package_exports = (paths) => {
164
173
  }
165
174
  else if (path.endsWith('.ts') && !path.endsWith('.d.ts')) {
166
175
  const js_path = replace_extension(path, '.js');
167
- const key = path === 'index.ts' ? '.' : './' + js_path;
176
+ const key = is_index(path) ? '.' : './' + js_path;
168
177
  exports[key] = {
169
178
  default: IMPORT_PREFIX + js_path,
170
179
  types: IMPORT_PREFIX + replace_extension(path, '.d.ts'),
171
180
  };
172
181
  }
173
182
  else if (path.endsWith('.js')) {
174
- const key = path === 'index.js' ? '.' : './' + path;
183
+ const key = is_index(path) ? '.' : './' + path;
175
184
  exports[key] = {
176
185
  default: IMPORT_PREFIX + path,
177
186
  types: IMPORT_PREFIX + replace_extension(path, '.d.ts'), // assuming JSDoc types
@@ -45,6 +45,7 @@ test('serialize_package_json fails with bad data', async () => {
45
45
  });
46
46
  test('to_package_exports', async () => {
47
47
  assert.equal(to_package_exports(['a/b.ts']), {
48
+ './package.json': './package.json',
48
49
  './a/b.js': {
49
50
  default: './dist/a/b.js',
50
51
  types: './dist/a/b.d.ts',
@@ -54,7 +55,13 @@ test('to_package_exports', async () => {
54
55
  'a/b/Some_Test_Svelte.svelte',
55
56
  'a/b/some_test_ts.ts',
56
57
  'a/b/some_test_json.json',
58
+ 'index.ts',
57
59
  ]), {
60
+ '.': {
61
+ default: './dist/index.js',
62
+ types: './dist/index.d.ts',
63
+ },
64
+ './package.json': './package.json',
58
65
  './a/b/some_test_json.json': {
59
66
  default: './dist/a/b/some_test_json.json',
60
67
  },
@@ -1,7 +1,8 @@
1
1
  import { z } from 'zod';
2
2
  import { type Task } from './task.js';
3
3
  export declare const Args: z.ZodObject<{
4
- branch: z.ZodDefault<z.ZodString>;
4
+ branch: z.ZodDefault<z.ZodBranded<z.ZodString, "Git_Branch">>;
5
+ origin: z.ZodDefault<z.ZodBranded<z.ZodString, "Git_Origin">>;
5
6
  changelog: z.ZodDefault<z.ZodString>;
6
7
  preserve_changelog: z.ZodDefault<z.ZodBoolean>;
7
8
  dry: z.ZodDefault<z.ZodBoolean>;
@@ -11,7 +12,8 @@ export declare const Args: z.ZodObject<{
11
12
  'no-install': z.ZodDefault<z.ZodBoolean>;
12
13
  }, "strict", z.ZodTypeAny, {
13
14
  install: boolean;
14
- branch: string;
15
+ origin: string & z.BRAND<"Git_Origin">;
16
+ branch: string & z.BRAND<"Git_Branch">;
15
17
  changelog: string;
16
18
  'no-install': boolean;
17
19
  check: boolean;
@@ -20,6 +22,7 @@ export declare const Args: z.ZodObject<{
20
22
  'no-check': boolean;
21
23
  }, {
22
24
  branch?: string | undefined;
25
+ origin?: string | undefined;
23
26
  changelog?: string | undefined;
24
27
  preserve_changelog?: boolean | undefined;
25
28
  dry?: boolean | undefined;
@@ -9,6 +9,7 @@ import { is_this_project_gro } from './paths.js';
9
9
  import { has_sveltekit_library } from './gro_plugin_sveltekit_library.js';
10
10
  import { update_changelog } from './changelog.js';
11
11
  import { load_from_env } from './env.js';
12
+ import { Git_Branch, Git_Origin, git_checkout, git_fetch, git_pull } from './git.js';
12
13
  // publish.task.ts
13
14
  // - usage: `gro publish patch`
14
15
  // - forwards args to `npm version`: https://docs.npmjs.com/v6/commands/npm-version
@@ -17,7 +18,8 @@ import { load_from_env } from './env.js';
17
18
  // - syncs commits and tags to the configured main branch
18
19
  export const Args = z
19
20
  .object({
20
- branch: z.string({ description: 'branch to publish from' }).default('main'),
21
+ branch: Git_Branch.describe('branch to publish from').default('main'),
22
+ origin: Git_Origin.describe('git origin to publish from').default('origin'),
21
23
  changelog: z
22
24
  .string({ description: 'file name and path of the changelog' })
23
25
  .default('CHANGELOG.md'),
@@ -43,7 +45,7 @@ export const task = {
43
45
  summary: 'bump version, publish to npm, and git push',
44
46
  Args,
45
47
  run: async ({ args, log, invoke_task }) => {
46
- const { branch, changelog, preserve_changelog, dry, check, install } = args;
48
+ const { branch, changelog, preserve_changelog, dry, check, install, origin } = args;
47
49
  if (dry) {
48
50
  log.info(green('dry run!'));
49
51
  }
@@ -59,9 +61,9 @@ export const task = {
59
61
  throw new Task_Error('changeset command not found: install @changesets/cli locally or globally');
60
62
  }
61
63
  // Make sure we're on the right branch:
62
- await spawn('git', ['fetch', 'origin', branch]);
63
- await spawn('git', ['checkout', branch]);
64
- await spawn('git', ['pull', 'origin', branch]);
64
+ await git_fetch(origin, branch);
65
+ await git_checkout(branch);
66
+ await git_pull(origin, branch);
65
67
  // Check before proceeding.
66
68
  if (check) {
67
69
  await invoke_task('check', { workspace: true });
@@ -10,6 +10,7 @@ test('to_package_modules', async () => {
10
10
  'fixtures/modules/some_test_ts.ts',
11
11
  'fixtures/modules/some_test_json.json',
12
12
  ]), undefined, paths.source), {
13
+ './package.json': { path: 'package.json', declarations: [] },
13
14
  './fixtures/modules/some_test_css.css': {
14
15
  path: 'fixtures/modules/some_test_css.css',
15
16
  declarations: [],
@@ -2,12 +2,18 @@ import { z } from 'zod';
2
2
  import type { Task } from './task.js';
3
3
  export declare const Args: z.ZodObject<{
4
4
  _: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
5
+ origin: z.ZodDefault<z.ZodBranded<z.ZodString, "Git_Origin">>;
6
+ force: z.ZodDefault<z.ZodBoolean>;
5
7
  dry: z.ZodDefault<z.ZodBoolean>;
6
8
  }, "strict", z.ZodTypeAny, {
7
9
  _: string[];
10
+ origin: string & z.BRAND<"Git_Origin">;
8
11
  dry: boolean;
12
+ force: boolean;
9
13
  }, {
10
14
  _?: string[] | undefined;
15
+ origin?: string | undefined;
16
+ force?: boolean | undefined;
11
17
  dry?: boolean | undefined;
12
18
  }>;
13
19
  export type Args = z.infer<typeof Args>;
@@ -1,9 +1,12 @@
1
1
  import { spawn } from '@ryanatkn/belt/process.js';
2
2
  import { z } from 'zod';
3
3
  import { load_package_json } from './package_json.js';
4
+ import { Git_Origin, git_pull } from './git.js';
4
5
  export const Args = z
5
6
  .object({
6
7
  _: z.array(z.string(), { description: 'names of deps to exclude from the upgrade' }).default([]),
8
+ origin: Git_Origin.describe('git origin to deploy to').default('origin'),
9
+ force: z.boolean({ description: 'if true, print out the planned upgrades' }).default(false),
7
10
  dry: z.boolean({ description: 'if true, print out the planned upgrades' }).default(false),
8
11
  })
9
12
  .strict();
@@ -11,17 +14,22 @@ export const task = {
11
14
  summary: 'upgrade deps',
12
15
  Args,
13
16
  run: async ({ args, log, invoke_task }) => {
14
- const { _, dry } = args;
17
+ const { _, origin, force, dry } = args;
18
+ // TODO maybe a different task that pulls and does other things, like `gro ready`
19
+ await git_pull(origin);
15
20
  const package_json = await load_package_json();
16
21
  const deps = to_deps(package_json).filter((d) => !_.includes(d.key));
17
22
  const upgrade_items = to_upgrade_items(deps);
23
+ log.info(`upgrading:`, upgrade_items.join(' '));
24
+ const install_args = ['install'].concat(upgrade_items);
18
25
  if (dry) {
26
+ install_args.push('--dry-run');
19
27
  log.info(`deps`, deps);
20
- log.info(`upgrade_items`, upgrade_items);
21
- return;
22
28
  }
23
- log.info(`upgrading:`, upgrade_items.join(' '));
24
- await spawn('npm', ['i'].concat(upgrade_items));
29
+ if (force) {
30
+ install_args.push('--force');
31
+ }
32
+ await spawn('npm', install_args);
25
33
  await invoke_task('sync');
26
34
  },
27
35
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ryanatkn/gro",
3
- "version": "0.113.0",
3
+ "version": "0.114.0",
4
4
  "description": "task runner and toolkit extending SvelteKit",
5
5
  "icon": "🌰",
6
6
  "public": true,
@@ -111,6 +111,7 @@
111
111
  "default": "./dist/index.js",
112
112
  "types": "./dist/index.d.ts"
113
113
  },
114
+ "./package.json": "./package.json",
114
115
  "./args.js": {
115
116
  "default": "./dist/args.js",
116
117
  "types": "./dist/args.d.ts"