webpack-loader-clarity 1.2.0 → 1.4.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.
package/README.md CHANGED
@@ -25,6 +25,7 @@ when the component loads.
25
25
  |---|---|---|
26
26
  | `css` | `'inject'` | `'inject'`: each component adds its own `<style>`. `'import'`: the component's CSS becomes a module named `<file>.clarity.css`, and the rules you wrote for `.css` files take it from there. `false`: the CSS is dropped. |
27
27
  | `types` | `false` | Also emit a `.d.ts` for every component. |
28
+ | `typescript` | by the project | A component is read as TypeScript where the project has a `tsconfig.json` and `typescript` installed (Clarity.js 1.4). `false` reads every component as JavaScript; a `typescript` module is the one to read with. |
28
29
  | `sourceMap` | webpack's `devtool` | |
29
30
 
30
31
  ## CSS through your own rules
package/index.cjs CHANGED
@@ -8,7 +8,9 @@
8
8
  *
9
9
  * Options: css 'inject' (default: each component adds its own <style>), 'import' (the CSS goes
10
10
  * through your own `.css` rules: css-loader, MiniCssExtractPlugin, …) or false; types (also emit
11
- * a .d.ts); sourceMap; runtimePath; routerPath.
11
+ * a .d.ts); typescript (a `typescript` module to read components with, or false for JavaScript;
12
+ * by default the project decides: TypeScript where it has a tsconfig.json and `typescript`);
13
+ * sourceMap; runtimePath; routerPath.
12
14
  *
13
15
  * webpack loads a loader with require(). The compiler is an ES module, so it is imported the
14
16
  * first time a file needs it. All of the work is the framework's own
@@ -25,13 +27,13 @@ const CSS_LOADER = require.resolve('./css.cjs');
25
27
  module.exports = function clarityLoader(source) {
26
28
  const done = this.async(), file = this.resourcePath;
27
29
  const options = (typeof this.getOptions === 'function' ? this.getOptions() : this.query) || {};
28
- const { runtimePath, routerPath, css = 'inject', types = false } = options;
30
+ const { runtimePath, routerPath, css = 'inject', types = false, typescript } = options;
29
31
  const sourceMap = options.sourceMap ?? this.sourceMap ?? false;
30
32
  if (css !== 'inject' && css !== 'import' && css !== false) return done(new Error(`webpack-loader-clarity: css must be 'inject', 'import' or false, not ${JSON.stringify(css)}`));
31
33
  load().then(({ transformComponent, injectCss }) => {
32
34
  let made;
33
35
  try {
34
- made = transformComponent(source, file, { runtimePath, routerPath, sourceMap, types });
36
+ made = transformComponent(source, file, { runtimePath, routerPath, sourceMap, types, typescript });
35
37
  } catch (err) {
36
38
  const shown = new Error(err.frame ? `${err.message}\n${err.frame}` : err.message);
37
39
  shown.name = 'ClarityError'; shown.hideStack = true;
package/index.d.ts CHANGED
@@ -3,6 +3,8 @@ export interface ClarityLoaderOptions {
3
3
  css?: 'inject' | 'import' | false;
4
4
  /** Also emit a `.d.ts` for every component. */
5
5
  types?: boolean;
6
+ /** Read components as TypeScript with this `typescript` module, or `false` for JavaScript. Default: the project decides (a tsconfig.json, and `typescript` installed). */
7
+ typescript?: object | false;
6
8
  sourceMap?: boolean;
7
9
  runtimePath?: string;
8
10
  routerPath?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpack-loader-clarity",
3
- "version": "1.2.0",
3
+ "version": "1.4.0",
4
4
  "description": "Webpack 5 loader for Clarity.js .clarity components: compiles them, handles their CSS, and can turn a pages folder into routes",
5
5
  "main": "index.cjs",
6
6
  "files": [