@wix/origami-transforms 0.1.1 → 0.1.2

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.
@@ -3,6 +3,22 @@ export function createTransformPipeline({ layout, jsxPlugins, cssPlugins }: {
3
3
  jsxPlugins?: readonly import("./types.js").JsxTransformPlugin[];
4
4
  cssPlugins?: readonly import("./types.js").CssTransformPlugin[];
5
5
  }): {
6
+ /** Whether any JSX transform selects this module (structure.jsx/.tsx by default).
7
+ * @param {string} id
8
+ * @param {{ ssr?: boolean | undefined }} [contextOptions] */
9
+ appliesTo: (id: string, { ssr }?: {
10
+ ssr?: boolean | undefined;
11
+ }) => boolean;
12
+ /** Run the shared checks with JSX and TypeScript preserved for the adapter's compiler.
13
+ * @param {string} code
14
+ * @param {string} id
15
+ * @param {{ ssr?: boolean | undefined }} [contextOptions] */
16
+ transformJsx: (code: string, id: string, { ssr }?: {
17
+ ssr?: boolean | undefined;
18
+ }) => Promise<{
19
+ code: any;
20
+ map: any;
21
+ }>;
6
22
  postcssPlugin: {
7
23
  postcssPlugin: string;
8
24
  Once(root: any, { result }: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/origami-transforms",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Babel and PostCSS checks and transforms for Wix origami page files.",
5
5
  "main": "./src/index.js",
6
6
  "files": [
@@ -54,5 +54,5 @@
54
54
  },
55
55
  "type": "module",
56
56
  "types": "./dist/index.d.ts",
57
- "falconPackageHash": "f8c86a6c866adc481be5b9391cc6d6aee64062877e89a73c69a386e9"
57
+ "falconPackageHash": "bfbe3e19687be417c93cd5eb07f45cc936aa654b83b1cb5958af7a59"
58
58
  }
@@ -1,4 +1,5 @@
1
1
  // Select and cache transform plugins by stage, file, and SSR context.
2
+ import { transformAsync } from '@babel/core'
2
3
  import { cssPlugins as defaultCssPlugins } from '../cssPlugins/index.js'
3
4
  import { jsxPlugins as defaultJsxPlugins } from '../jsxPlugins/index.js'
4
5
  import { createContextFactory } from './context.js'
@@ -45,9 +46,41 @@ export const createTransformPipeline = ({ layout, jsxPlugins = defaultJsxPlugins
45
46
  /** @type {Map<string, Set<string>>} stylesheet whose last CSS run failed -> the files it declared */
46
47
  const cssFailures = new Map()
47
48
 
49
+ const babelOptionsFor = createBabelOptionsSelector({ contextFor, selectPlugins: selectFor('jsx') })
50
+
48
51
  return {
52
+ /** Whether any JSX transform selects this module (structure.jsx/.tsx by default).
53
+ * @param {string} id
54
+ * @param {{ ssr?: boolean | undefined }} [contextOptions] */
55
+ appliesTo: (id, { ssr = false } = {}) => selectFor('jsx')(contextFor(id, { ssr })).length > 0,
56
+
57
+ /** Run the shared checks with JSX and TypeScript preserved for the adapter's compiler.
58
+ * @param {string} code
59
+ * @param {string} id
60
+ * @param {{ ssr?: boolean | undefined }} [contextOptions] */
61
+ transformJsx: async (code, id, { ssr = false } = {}) => {
62
+ const filename = id.split('?', 1)[0]
63
+ const options = babelOptionsFor(id, { ssr })
64
+ const result = await transformAsync(code, {
65
+ ...options,
66
+ filename,
67
+ babelrc: false,
68
+ configFile: false,
69
+ sourceMaps: true,
70
+ parserOpts: {
71
+ ...options.parserOpts,
72
+ plugins: [...new Set([
73
+ 'jsx',
74
+ ...(filename.endsWith('.tsx') ? ['typescript'] : []),
75
+ ...(options.parserOpts?.plugins ?? []),
76
+ ])],
77
+ },
78
+ })
79
+ return { code: result.code, map: result.map }
80
+ },
81
+
49
82
  postcssPlugin: createCssPostcssPlugin({ contextFor, selectPlugins: selectFor('css'), failures: cssFailures }),
50
- babelOptionsFor: createBabelOptionsSelector({ contextFor, selectPlugins: selectFor('jsx') }),
83
+ babelOptionsFor,
51
84
 
52
85
  /** Whether a stylesheet whose last CSS run failed declared `file`, so an edit to it may fix the stylesheet. */
53
86
  failedStylesheetDependsOn: file => [...cssFailures.values()].some(files => files.has(file)),