postcss-lightningcss icon indicating copy to clipboard operation
postcss-lightningcss copied to clipboard

New: Add bundle option

Open jonnitto opened this issue 1 year ago • 9 comments

Closes #155

jonnitto avatar Nov 26 '24 18:11 jonnitto

Hi @jonnitto, thanks for the suggestion and contribution. This looks interesting. Can you please add one test to make sure this does what it is supposed to ?

Thanks

onigoetz avatar Nov 26 '24 19:11 onigoetz

I try to add a test, but I failed:

I've created a file named import.css in the folder fixtures with following content:

.foo {
    background: red;
}

but the test don't get the path correctly:

test('Should import CSS file', (t) => {
  t.plan(1);
  return postcss()
    .use(postcssLightningcss({
      bundle: true,
    }))
    .process('@import "./fixtures/import.css";', {
      from: path.join(__dirname, 'input.css'),
    })
    .then((result) => t.is(result.css, '.foo{background:red}'));
});

I always get following error:

  imports › Should import CSS file

  Rejected promise returned by test. Reason:

  SyntaxError {
    data: 'ResolverError',
    message: 'No such file or directory (os error 2)',
  }

  SyntaxError: No such file or directory (os error 2)
      at OnceExit (/PATH_TO_FOLDER/postcss-lightningcss/src/index.js:39:19)
      at LazyResult.runAsync (/PATH_TO_FOLDER/postcss-lightningcss/node_modules/postcss/lib/lazy-result.js:298:21)
      at LazyResult.async (/PATH_TO_FOLDER/postcss-lightningcss/node_modules/postcss/lib/lazy-result.js:160:30)
      at LazyResult.then (/PATH_TO_FOLDER/postcss-lightningcss/node_modules/postcss/lib/lazy-result.js:404:17)
      at /PATH_TO_FOLDER/postcss-lightningcss/test/imports.js:53:6
      at Test.callFn (file:///PATH_TO_FOLDER/postcss-lightningcss/node_modules/ava/lib/test.js:525:26)
      at Test.run (file:///PATH_TO_FOLDER/postcss-lightningcss/node_modules/ava/lib/test.js:534:33)
      at Runner.runSingle (file:///PATH_TO_FOLDER/postcss-lightningcss/node_modules/ava/lib/runner.js:281:33)
      at Runner.runTest (file:///PATH_TO_FOLDER/postcss-lightningcss/node_modules/ava/lib/runner.js:363:30)
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

  ─

jonnitto avatar Nov 26 '24 21:11 jonnitto

I pushed the tests, even if the last two are still failing…

jonnitto avatar Nov 26 '24 21:11 jonnitto

Awesome, no worries, that's good enough, I'll have a look tonight

onigoetz avatar Nov 27 '24 07:11 onigoetz

Hmm, so I looked into this and have bad news.

the reason the test fails with No such file or directory (os error 2) is that it tries to find the source file that's passed to postcss.

Because the bundle function expects a file as input, the code option I use for the rest doesn't work.

I think this means that this feature isn't possible in the context of postcss

onigoetz avatar Nov 27 '24 20:11 onigoetz

Hm, that's pity. Would it be ok for you to remove the failing tests and create a release anyway? This feature is crucial for me and it allows to remove even one more PostCSS plugin

jonnitto avatar Nov 28 '24 20:11 jonnitto

I don't understand, a release would be of no use to you.

The issue is not with the tests, it simply won't work because it expects a file as input.

onigoetz avatar Nov 28 '24 21:11 onigoetz

Strange. In my enviroment the setting works fine. If i set bundle to true, the CSS get's bundled

jonnitto avatar Nov 29 '24 10:11 jonnitto

Sorry for the delay.

I think the reason why you don't see this error is that the input file you specify is the one that is read by lightningcss.

To try this hypothesis try the following

  1. create a css file with some css in it
  2. create a postcss config with a few rules before postcss-lightningcss
  3. use bundle

The output of the bundled file should not have the modifications performed before passing to postcss-lightningcss as it simply read the file from disk instead of reading the serialized version passed to it by postcss-lightningcss

onigoetz avatar Dec 16 '24 21:12 onigoetz

Closing this as postcss-lightningcss won't be compatible with the bundle options for the reasons listed above

onigoetz avatar Aug 28 '25 19:08 onigoetz