@usequeek/create-theme 0.10.0 → 0.10.1

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.
package/dist/add.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
2
- import { join, relative, resolve } from 'node:path';
2
+ import { dirname, isAbsolute, join, relative, resolve } from 'node:path';
3
3
  import { designsOf, groupTemplates, loadContext, TEMPLATE_DESIGNS_MAX, } from '@usequeek/theme-check';
4
4
  import { appendDemoEntry, setDesignLabel } from './config-edit.js';
5
5
  import { bundledLists, createLists, nearest } from './lists.js';
@@ -248,10 +248,12 @@ export async function planAddPage(themeDir, input) {
248
248
  export function applyAddPlan(plan) {
249
249
  for (const write of plan.writes) {
250
250
  const relativePath = relative(plan.dir, write.path);
251
- if (relativePath.startsWith('..') || relativePath === '') {
251
+ // `relative` answers with the platform's separator (`demos\x.json` on Windows), and
252
+ // with an absolute path when the file is on another drive.
253
+ if (relativePath === '' || relativePath.startsWith('..') || isAbsolute(relativePath)) {
252
254
  throw new Error(`Refusing to write outside the theme folder: ${write.path}`);
253
255
  }
254
- mkdirSync(join(plan.dir, relativePath.split('/').slice(0, -1).join('/')), { recursive: true });
256
+ mkdirSync(dirname(write.path), { recursive: true });
255
257
  writeFileSync(write.path, write.content);
256
258
  }
257
259
  }
@@ -102,6 +102,16 @@ function lastSignificantChar(source, from, to) {
102
102
  return last;
103
103
  }
104
104
  const newlineOf = (source) => (source.includes('\r\n') ? '\r\n' : '\n');
105
+ /**
106
+ * Edit a CRLF file (a Windows checkout, many Windows editors) as LF and give it back
107
+ * as CRLF. The parser's node offsets do not line up with a CRLF source, so an edit
108
+ * spliced at them lands mid-line and rewrites its neighbours (Windows CI, 29/9/26).
109
+ */
110
+ function preservingLineEndings(source, edit) {
111
+ if (!source.includes('\r\n'))
112
+ return edit(source);
113
+ return edit(source.replace(/\r\n/g, '\n')).replace(/\r?\n/g, '\r\n');
114
+ }
105
115
  /**
106
116
  * `key: value` freshly rendered, spliced before the object's closing brace.
107
117
  * The text between the last property and the brace decides the comma: a
@@ -133,6 +143,9 @@ function insertProperty(source, obj, key, renderedValue) {
133
143
  }
134
144
  /** Push a demos[] entry, creating the array when the config has none. Everything else stays byte-identical. */
135
145
  export function appendDemoEntry(source, entry) {
146
+ return preservingLineEndings(source, (lf) => appendDemoEntryLf(lf, entry));
147
+ }
148
+ function appendDemoEntryLf(source, entry) {
136
149
  const config = configObjectOf(source);
137
150
  const demos = objectProperty(config, 'demos');
138
151
  const newline = newlineOf(source);
@@ -168,6 +181,9 @@ export function appendDemoEntry(source, entry) {
168
181
  * or a demos[] entry, replacing it when present. Everything else stays byte-identical.
169
182
  */
170
183
  export function setDesignLabel(source, designId, label) {
184
+ return preservingLineEndings(source, (lf) => setDesignLabelLf(lf, designId, label));
185
+ }
186
+ function setDesignLabelLf(source, designId, label) {
171
187
  const config = configObjectOf(source);
172
188
  let target = null;
173
189
  if (designId === 'default') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usequeek/create-theme",
3
- "version": "0.10.0",
3
+ "version": "0.10.1",
4
4
  "description": "npm create @usequeek/theme — start a Queek storefront theme from the official starter.",
5
5
  "license": "MIT",
6
6
  "type": "module",