nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: Aleph-Alpha/ts-rs
Pull request #358 (2024-10-07 05:36:41)

feat(serde-json-impl): handle bool for serde_json::Value
## Goal

- Adds `boolean` to the TS type for `serde_json::Value`

### Notes

- As far as I know, `boolean` is a correct type in JSONs, and is one of the possible variants of `serde_json::Value`, so I think it makes sense to add it to the generated TS type

## Changes

- Added new variant to the enum `TsJsonValue` => `Boolean(bool)` 
- Added `| boolean` in the unit tests for `serde-json-impl` feature

## Checklist

- [x] I have followed the steps listed in the [Contributing guide](https://github.com/Aleph-Alpha/ts-rs/blob/main/CONTRIBUTING.md).
- [x] If necessary, I have added documentation related to the changes made.
- [x] I have added or updated the tests related to the changes made.



Patch:
diff --git a/ts-rs/src/serde_json.rs b/ts-rs/src/serde_json.rs
index a5e63ed..a1367bc 100644
--- a/ts-rs/src/serde_json.rs
+++ b/ts-rs/src/serde_json.rs
@@ -12,6 +12,7 @@ use super::{impl_primitives, impl_shadow, TS};
 pub enum TsJsonValue {
     Number(i32),
     String(String),
+    Boolean(bool),
     Array(Vec<TsJsonValue>),
     Object(HashMap<String, TsJsonValue>),
 }


Test patch:
diff --git a/ts-rs/tests/integration/serde_json.rs b/ts-rs/tests/integration/serde_json.rs
index fc0a113..7b130d4 100644
--- a/ts-rs/tests/integration/serde_json.rs
+++ b/ts-rs/tests/integration/serde_json.rs
@@ -24,7 +24,7 @@ fn using_serde_json() {
     );
     assert_eq!(
         serde_json::Value::decl(),
-        "type JsonValue = number | string | Array<JsonValue> | { [key in string]?: JsonValue };",
+        "type JsonValue = number | string | boolean | Array<JsonValue> | { [key in string]?: JsonValue };",
     );
 
     assert_eq!(
@@ -53,7 +53,7 @@ fn inlined_value() {
     assert_eq!(
         InlinedValue::decl(),
         "type InlinedValue = { \
-            any: number | string | Array<JsonValue> | { [key in string]?: JsonValue }, \
+            any: number | string | boolean | Array<JsonValue> | { [key in string]?: JsonValue }, \
          };"
     );
 }
Repository: maizzle/framework
Pull request #196 (2020-05-28 14:22:17)

feat(todisk): support multiple asset paths
This PR adds support for using multiple asset paths:

```js
// config.js
module.exports = {
  build: {
    assets: {
      source: ['src/assets/images', 'src/fonts'],
      destination: 'assets',
    },
    // ...
  }
}
```


Patch:
diff --git a/src/generators/output/to-disk.js b/src/generators/output/to-disk.js
index 922f019..d6dfabc 100644
--- a/src/generators/output/to-disk.js
+++ b/src/generators/output/to-disk.js
@@ -111,8 +111,12 @@ module.exports = async (env, spinner, config = {}) => {
 
   const assets = {source: '', destination: 'assets', ...getPropValue(config, 'build.assets')}
 
-  if (fs.pathExistsSync(assets.source)) {
-    await fs.copy(assets.source, `${outputDir}/${assets.destination}`)
+  if (Array.isArray(assets.source)) {
+    await asyncForEach(assets.source, async source => {
+      await fs.copy(source, `${outputDir}/${assets.destination}`).catch(error => spinner.warn(error.message))
+    })
+  } else {
+    await fs.copy(assets.source, `${outputDir}/${assets.destination}`).catch(error => spinner.warn(error.message))
   }
 
   const files = await glob(`${outputDir}/**/*.*`)


Test patch:
diff --git a/test/test-todisk.js b/test/test-todisk.js
index 6e0fedb..ca073c3 100644
--- a/test/test-todisk.js
+++ b/test/test-todisk.js
@@ -230,3 +230,24 @@ test('runs the `afterBuild` event', async t => {
 
   t.deepEqual(t.context.afterBuild, files)
 })
+
+test('supports multiple asset paths', async t => {
+  await Maizzle.build('production', {
+    build: {
+      fail: 'silent',
+      destination: {
+        path: t.context.folder
+      },
+      templates: {
+        root: 'test/stubs/templates'
+      },
+      assets: {
+        source: ['test/stubs/assets', 'test/stubs/plaintext'],
+        destination: 'extras'
+      }
+    }
+  })
+
+  t.true(fs.existsSync(`${t.context.folder}/extras/foo.bar`))
+  t.true(fs.existsSync(`${t.context.folder}/extras/plaintext.html`))
+})
Repository: maizzle/framework
Pull request #350 (2020-11-06 14:49:41)

feat(posthtml): define top-level locals in config
This PR adds support for user-defined top-level config objects.

In other words, you can define [variables](https://maizzle.com/docs/layouts/#variables) (a.k.a. `locals`) outside of the `page` object.

Simply add a `locals` object to your `config.js`:

```js
module.exports = {
  locals: {
    company: {
      name: 'Spacely Space Sprockets, Inc.'
    }
  }
}
```

You can access `company.name` directly, no need for the `page` object:

```html
<h1>{{ company.name }}</h1>
```

Alternatively, you can also create a top-level config object by configuring `posthtml-expressions` and passing in `locals` there:

```js
module.exports = {
  build: {
    posthtml: {
      expressions: {
        locals: {
          foo: 'bar'
        }
      }
    }
  }
}
```

```html
<p>'foo' is {{ foo }}</p>
```

Note: overwriting the `page` object is not possible, so if you do something like this:

```js
module.exports = {
  locals: {
    page: {
      foo: 'bar'
    }
  }
}
```

... Maizzle will overwrite that `locals.page` object, and `foo` will be `undefined`.


Patch:
diff --git a/src/generators/posthtml.js b/src/generators/posthtml.js
index 77513b9..fb81c10 100644
--- a/src/generators/posthtml.js
+++ b/src/generators/posthtml.js
@@ -21,7 +21,12 @@ module.exports = async (html, config) => {
   const posthtmlPlugins = getPropValue(config, 'build.posthtml.plugins') || []
 
   const expressionsOptions = getPropValue(config, 'build.posthtml.expressions') || {}
-  const expressionsPlugin = expressions({...expressionsOptions, locals: {page: config}})
+  const locals = {
+    ...getPropValue(expressionsOptions, 'locals') || {},
+    ...getPropValue(config, 'locals') || {},
+    page: config
+  }
+  const expressionsPlugin = expressions({...expressionsOptions, locals})
 
   return posthtml([
     layouts({strict: false, ...layoutsOptions}),


Test patch:
diff --git a/test/test-tostring.js b/test/test-tostring.js
index 4a4319b..bff32fb 100644
--- a/test/test-tostring.js
+++ b/test/test-tostring.js
@@ -73,3 +73,51 @@ test('runs the `afterTransformers` event', async t => {
 
   t.is(result, `<div>bar</div>`)
 })
+
+test('multiple locals', async t => {
+  const result = await renderString(`{{ page.one }}, {{ two }}, {{ three }}`, {
+    maizzle: {
+      one: 1,
+      build: {
+        posthtml: {
+          expressions: {
+            locals: {
+              two: 2
+            }
+          }
+        }
+      },
+      locals: {
+        three: 3
+      }
+    }
+  })
+
+  t.is(result, `1, 2, 3`)
+})
+
+test('prevents overwriting page object', async t => {
+  const result = await renderString(`{{ page.one }}, {{ two }}, {{ three }}`, {
+    maizzle: {
+      one: 1,
+      build: {
+        posthtml: {
+          expressions: {
+            locals: {
+              page: {
+                two: 2
+              }
+            }
+          }
+        }
+      },
+      locals: {
+        page: {
+          three: 3
+        }
+      }
+    }
+  })
+
+  t.is(result, `1, undefined, undefined`)
+})
Repository: maizzle/framework
Pull request #638 (2022-03-04 15:42:48)

feat: support file path sources
This PR adds support for file path sources, so you can compile just one template when developing locally with the `maizzle build` command:

```js
module.exports = {
  build: {
    templates: {
      source: 'src/templates/index.html',
      destination: {
        path: 'build_local',
      },
    },
  }
}
```



Patch:
diff --git a/src/generators/output/to-disk.js b/src/generators/output/to-disk.js
index ac97445..9d8bf70 100644
--- a/src/generators/output/to-disk.js
+++ b/src/generators/output/to-disk.js
@@ -69,8 +69,15 @@ module.exports = async (env, spinner, config) => {
 
     // Parse each template source
     await asyncForEach(templateSource, async source => {
+      /**
+       * Copy single-file sources correctly
+       * If `src` is a file, `dest` cannot be a directory
+       * https://github.com/jprichardson/node-fs-extra/issues/323
+       */
+      const out = fs.lstatSync(source).isFile() ? `${outputDir}/${path.basename(source)}` : outputDir
+
       await fs
-        .copy(source, outputDir)
+        .copy(source, out)
         .then(async () => {
           const extensions = Array.isArray(templateConfig.filetypes)
             ? templateConfig.filetypes.join('|')
diff --git a/src/generators/tailwindcss.js b/src/generators/tailwindcss.js
index 7738ee8..17b00b6 100644
--- a/src/generators/tailwindcss.js
+++ b/src/generators/tailwindcss.js
@@ -73,6 +73,13 @@ module.exports = {
           return {raw: '', extension: 'html'}
         }
 
+        // Support single-file sources i.e. src/templates/index.html
+        if (typeof source === 'string' && Boolean(path.extname(source))) {
+          config.content.files.push(source)
+
+          return {raw: '', extension: 'html'}
+        }
+
         return `${source}/**/*.*`
       })
 


Test patch:
diff --git a/test/test-tailwind.js b/test/test-tailwind.js
index 0ee24b6..afca689 100644
--- a/test/test-tailwind.js
+++ b/test/test-tailwind.js
@@ -64,7 +64,7 @@ test('works with custom `files` sources', async t => {
   t.true(css.includes('.hidden'))
 })
 
-test('uses maizzle template paths when purging', async t => {
+test('uses maizzle template path as content source', async t => {
   const css = await Tailwind.compile(
     '@tailwind utilities;',
     '<div></div>',
@@ -81,6 +81,23 @@ test('uses maizzle template paths when purging', async t => {
   t.true(css.includes('.hidden'))
 })
 
+test('uses maizzle template path as content source (single file)', async t => {
+  const css = await Tailwind.compile(
+    '@tailwind utilities;',
+    '<div></div>',
+    {},
+    {
+      build: {
+        templates: {
+          source: './test/stubs/tailwind/preserve.html'
+        }
+      }
+    }
+  )
+
+  t.true(css.includes('.hidden'))
+})
+
 test('uses custom postcss plugins from the maizzle config', async t => {
   const maizzleConfig = {
     env: 'production',
Repository: maizzle/framework
Pull request #755 (2022-09-18 17:08:56)

feat: config.build.current
This PR adds `config.build.current`, an object containing a parsed path of the currently-processed template:

```js
{
    root: '',
    dir: 'build_production',
    base: 'example.html',
    ext: '.html',
    name: 'example'
}
```

Since Maizzle copies the source files to destination and then compiles them there, the parsed path is your `build.templates.destination.path`, hence the `build_production` directory.

Also, this is only available when using the CLI with `maizzle build` - there's no source file path when using the API.


Patch:
diff --git a/src/generators/output/to-disk.js b/src/generators/output/to-disk.js
index 9e621b2..c81befa 100644
--- a/src/generators/output/to-disk.js
+++ b/src/generators/output/to-disk.js
@@ -96,6 +96,8 @@ module.exports = async (env, spinner, config) => {
           }
 
           await asyncForEach(templates, async file => {
+            config.build.current = path.parse(file)
+
             const html = await fs.readFile(file, 'utf8')
 
             try {


Test patch:
diff --git a/test/test-todisk.js b/test/test-todisk.js
index ad7f1d6..15a7a19 100644
--- a/test/test-todisk.js
+++ b/test/test-todisk.js
@@ -509,3 +509,32 @@ test('throws if templates path is invalid (function)', async t => {
     })
   }, {instanceOf: TypeError})
 })
+
+test('sets config.build.current', async t => {
+  await Maizzle.build('maizzle-ci', {
+    build: {
+      fail: 'silent',
+      templates: {
+        source: 'test/stubs/templates',
+        destination: {
+          path: t.context.folder
+        }
+      }
+    },
+    events: {
+      beforeRender(html, config) {
+        t.context.current = config.build.current
+
+        return html
+      }
+    }
+  })
+
+  t.deepEqual(t.context.current, {
+    root: '',
+    dir: t.context.folder,
+    base: '1.html',
+    ext: '.html',
+    name: '1'
+  })
+})
Repository: maizzle/framework
Pull request #783 (2022-10-07 16:11:24)

fix: tailwindcss content sources
This PR fixes a performance issue where we always included `./src/**/*.*` in the `content` array when compiling Tailwind CSS.

This not only included a very broad pattern, but started significantly slowing builds down as more files were added to the `src` folder. It was especially noticeable when image files were added to `./src/assets`.

Now, the default `content` sources are:

```js
content: {
  files: [
    './src/components/**.html',
    './src/layouts/**.html',
    {raw: html, extension: 'html'}
  ]
}
```

... where `html` is the HTML string currently being processed.

If you add your own `content` key to `tailwind.config.js`, this will be overwritten to:

```js
{
  files: [
    ...config.content,
    {raw: html, extension: 'html'}
  ]
}
```

... meaning that you need to make sure to also add any paths to Components or Layouts:

```js
// tailwind.config.js

module.exports = {
  content: [
    './src/components/**.html',
    './src/layouts/**.html',
    // other content sources...
  ],
}
```


Patch:
diff --git a/src/generators/tailwindcss.js b/src/generators/tailwindcss.js
index 0d9089f..230dedd 100644
--- a/src/generators/tailwindcss.js
+++ b/src/generators/tailwindcss.js
@@ -35,7 +35,8 @@ module.exports = {
       important: true,
       content: {
         files: [
-          './src/**/*.*',
+          './src/components/**.html',
+          './src/layouts/**.html',
           {raw: html, extension: 'html'}
         ]
       }
@@ -46,7 +47,6 @@ module.exports = {
       config.content = {
         files: [
           ...config.content,
-          './src/**/*.*',
           {raw: html, extension: 'html'}
         ]
       }


Test patch:
diff --git a/test/test-tailwindcss.js b/test/test-tailwindcss.js
index 398fb42..ba6f2ed 100644
--- a/test/test-tailwindcss.js
+++ b/test/test-tailwindcss.js
@@ -111,5 +111,5 @@ test('uses custom postcss plugins from the maizzle config', async t => {
   const css = await Tailwind.compile('.test {transform: scale(0.5)}', '<div class="test">Test</a>', {}, maizzleConfig)
 
   t.not(css, undefined)
-  t.is(css.trim(), '.inline {display: inline !important} .table {display: table !important} .contents {display: contents !important} .truncate {overflow: hidden !important;text-overflow: ellipsis !important;white-space: nowrap !important} .uppercase {text-transform: uppercase !important} .lowercase {text-transform: lowercase !important} .capitalize {text-transform: capitalize !important} .test {-webkit-transform: scale(0.5);transform: scale(0.5)}')
+  t.is(css.trim(), '.test {-webkit-transform: scale(0.5);transform: scale(0.5)}')
 })
Repository: maizzle/framework
Pull request #793 (2022-10-12 11:17:06)

fix: remove empty style tags
This PR fixes an issue where empty `style` tags started being output in the compiled HTML after some updates to `removeInlinedSelectors`.



Patch:
diff --git a/src/transformers/removeInlinedSelectors.js b/src/transformers/removeInlinedSelectors.js
index b76f256..a0ecfe6 100644
--- a/src/transformers/removeInlinedSelectors.js
+++ b/src/transformers/removeInlinedSelectors.js
@@ -71,7 +71,12 @@ const plugin = posthtmlOptions => tree => {
         } catch {}
       })
 
-      node.content = root.toString()
+      node.content = root.toString().trim()
+
+      // Remove <style> tag if it ends up empty after processing
+      if (node.content.length === 0) {
+        node.tag = false
+      }
     }
 
     return node


Test patch:
diff --git a/test/test-transformers.js b/test/test-transformers.js
index 0c70bcc..1aea4b2 100644
--- a/test/test-transformers.js
+++ b/test/test-transformers.js
@@ -495,11 +495,10 @@ test('remove inlined selectors', async t => {
     </body>
   </html>`
 
-  const expectedWithOptions = `<!DOCTYPE html>
+  const expectedHTML = `<!DOCTYPE html>
   <html>
     <head>
-      <style>
-        .hover-text-blue:hover {
+      <style>.hover-text-blue:hover {
           color: #00a8ff;
         }
 
@@ -514,11 +513,8 @@ test('remove inlined selectors', async t => {
 
         @media (max-width: 600px) {
           .ignore {color: blue}
-        }
-      </style>
-      <style>
-        .keep {margin: 0}
-      </style>
+        }</style>
+      <style>.keep {margin: 0}</style>
     </head>
     <body>
       <div no-value id="keepId" class="keep foo-class" style="color: red; display: inline">
@@ -529,6 +525,30 @@ test('remove inlined selectors', async t => {
     </body>
   </html>`
 
+  const html2 = `<!DOCTYPE html>
+  <html>
+    <head><style>
+        img {
+          border: 0;
+          vertical-align: middle
+        }
+      </style></head>
+    <body>
+      <img src="https://example.com/image.jpg" style="border: 0; vertical-align: middle">
+    </body>
+  </html>`
+
+  const expectedNoEmptyStyleTags = `<!DOCTYPE html>
+  <html>
+    <head></head>
+    <body>
+      <img src="https://example.com/image.jpg" style="border: 0; vertical-align: middle">
+    </body>
+  </html>`
+
+  const basic = await Maizzle.removeInlinedClasses(html)
+  const noEmptyStyle = await Maizzle.removeInlinedClasses(html2)
+
   const withPostHTMLOptions = await Maizzle.removeInlinedClasses(html, {
     build: {
       posthtml: {
@@ -539,10 +559,9 @@ test('remove inlined selectors', async t => {
     }
   })
 
-  const basic = await Maizzle.removeInlinedClasses(html)
-
-  t.is(withPostHTMLOptions, expectedWithOptions)
-  t.is(basic, expectedWithOptions)
+  t.is(basic, expectedHTML)
+  t.is(withPostHTMLOptions, expectedHTML)
+  t.is(noEmptyStyle, expectedNoEmptyStyleTags)
 })
 
 test('remove inlined selectors (disabled)', async t => {
Repository: maizzle/framework
Pull request #817 (2022-10-21 10:30:12)

feat: disable filters
This PR adds the ability to completely disable filters in Maizzle by setting the option to `false` in your `config.js`:

```js
module.exports = {
  filters: false,
}
```



Patch:
diff --git a/src/transformers/filters/index.js b/src/transformers/filters/index.js
index 5efcb12..f7f94d2 100644
--- a/src/transformers/filters/index.js
+++ b/src/transformers/filters/index.js
@@ -8,6 +8,10 @@ const safeClassNames = require('posthtml-safe-class-names')
 const defaultConfig = require('../../generators/posthtml/defaultConfig')
 
 module.exports = async (html, config = {}, direct = false) => {
+  if (get(config, 'filters') === false) {
+    return html
+  }
+
   const filters = direct ?
     merge(defaultFilters, config) :
     merge(defaultFilters, get(config, 'filters', {}))


Test patch:
diff --git a/test/test-transformers.js b/test/test-transformers.js
index 56641a6..9cb74b9 100644
--- a/test/test-transformers.js
+++ b/test/test-transformers.js
@@ -361,6 +361,12 @@ test('filters (default)', async t => {
   t.is(html, await expected('filters'))
 })
 
+test('filters (disabled)', async t => {
+  const html = await Maizzle.withFilters('<p uppercase>test</p>', {filters: false})
+
+  t.is(html, '<p uppercase>test</p>')
+})
+
 test('filters (tailwindcss)', async t => {
   const html = await Maizzle.withFilters(
     `<style tailwindcss>
Repository: maizzle/framework
Pull request #856 (2022-12-09 14:30:36)

Add `shorthandCSS` to `postcss` transformer
Forgot to make the new `shorthandCSS` option available to this Transformer too.

Added now, so you can do this:

```html
<style postcss>
  .padded {
    @apply py-2 px-4;
  }
</style>
```

... and, as long as you have `shorthandCSS: true` in your `config.js`, get this:

```html
<style>
  .padded {
    padding: 8px 16px;
  }
</style>
```

Of course if you have `shorthandCSS: false`, it will not merge the rules and you'll get:

```html
<style>
  .padded {
    padding-top: 8px;
    padding-bottom: 8px;
    padding-left: 8px;
    padding-right: 8px;
  }
</style>
```



Patch:
diff --git a/src/generators/postcss.js b/src/generators/postcss.js
index 4e30cb8..416de6c 100644
--- a/src/generators/postcss.js
+++ b/src/generators/postcss.js
@@ -9,7 +9,9 @@ module.exports = {
     return postcss([
       postcssImport(),
       postcssNested(),
-      maizzleConfig.env === 'local' ? () => {} : mergeLonghand(),
+      get(maizzleConfig, 'shorthandCSS', get(maizzleConfig, 'shorthandInlineCSS')) === true ?
+        mergeLonghand() :
+        () => {},
       ...get(maizzleConfig, 'build.postcss.plugins', [])
     ])
       .process(css, {from: undefined})


Test patch:
diff --git a/test/test-tostring.js b/test/test-tostring.js
index db9a261..829d1c8 100644
--- a/test/test-tostring.js
+++ b/test/test-tostring.js
@@ -154,10 +154,12 @@ test('preserves css in marked style tags (tailwindcss)', async t => {
 })
 
 test('@import css files in marked style tags', async t => {
-  const source = `<style class="inline" postcss>@import "test/stubs/post.css";</style>`
-  const html = await renderString(source)
+  const source = `<style postcss>@import "test/stubs/post.css";</style>`
+  const html = await renderString(source, {
+    maizzle: {
+      shorthandCSS: true
+    }
+  })
 
-  t.is(html, `<style class="inline">div {
-  margin: 1px 2px 3px 4px;
-}</style>`)
+  t.is(html.replace(/\n {2,}/g, ''), `<style>div {margin: 1px 2px 3px 4px;\n}</style>`)
 })
diff --git a/test/test-transformers.js b/test/test-transformers.js
index f729924..0787bc7 100644
--- a/test/test-transformers.js
+++ b/test/test-transformers.js
@@ -360,7 +360,10 @@ test('filters (postcss)', async t => {
         margin-bottom: 3px;
         margin-left: 4px;
       }
-    </style>`
+    </style>`,
+    {
+      shorthandCSS: true
+    }
   )
 
   t.is(html.replace(/\n {2,}/g, ''), '<style>div {margin: 1px 2px 3px 4px;}</style>')