@ryanatkn/gro 0.113.1 → 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.
@@ -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.
@@ -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.1',
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.1',
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
  },
@@ -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: [],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ryanatkn/gro",
3
- "version": "0.113.1",
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"