Skip to content

Commit

Permalink
Chore: More sane config options
Browse files Browse the repository at this point in the history
  • Loading branch information
nmn committed Dec 1, 2023
1 parent 32d1d4e commit dc3cca7
Show file tree
Hide file tree
Showing 27 changed files with 304 additions and 300 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ function transform(source, opts = options) {
jsx,
[
stylexPlugin,
{
treeshakeCompensation: true,
...opts,
},
{ treeshakeCompensation: true, runtimeInjection: true, ...opts },
],
],
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function transform(source, opts = {}) {
parserOpts: {
flow: 'all',
},
plugins: [jsx, [stylexPlugin, opts]],
plugins: [jsx, [stylexPlugin, { runtimeInjection: true, ...opts }]],
}).code;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function transform(source, opts = {}) {
parserOpts: {
flow: 'all',
},
plugins: [flowPlugin, [stylexPlugin, opts]],
plugins: [flowPlugin, [stylexPlugin, { runtimeInjection: true, ...opts }]],
}).code;
}

Expand Down Expand Up @@ -805,7 +805,7 @@ describe('@stylexjs/babel-plugin', () => {
}
});
`,
{ stylexSheetName: '<>' },
{ runtimeInjection: false },
),
).toMatchInlineSnapshot(`
"import stylex from 'stylex';
Expand Down Expand Up @@ -984,7 +984,7 @@ describe('@stylexjs/babel-plugin', () => {
}
});
`,
{ stylexSheetName: '<>', styleResolution: 'property-specificity' },
{ runtimeInjection: false, styleResolution: 'property-specificity' },
),
).toMatchInlineSnapshot(`
"import stylex from 'stylex';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function transform(source, opts = {}) {
parserOpts: {
flow: 'all',
},
plugins: [[stylexPlugin, opts]],
plugins: [[stylexPlugin, { runtimeInjection: true, ...opts }]],
}).code;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function transform(source, opts = {}) {
parserOpts: {
flow: 'all',
},
plugins: [[stylexPlugin, opts]],
plugins: [[stylexPlugin, { runtimeInjection: true, ...opts }]],
}).code;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ function transform(source, opts = {}) {
},
plugins: [
jsx,
[stylexPlugin, { styleResolution: 'legacy-expand-shorthands', ...opts }],
[
stylexPlugin,
{
runtimeInjection: true,
styleResolution: 'legacy-expand-shorthands',
...opts,
},
],
],
}).code;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function transform(source, opts = {}) {
parserOpts: {
flow: 'all',
},
plugins: [[stylexPlugin, opts]],
plugins: [[stylexPlugin, { ...opts, runtimeInjection: true }]],
}).code;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function transform(source, opts = {}) {
parserOpts: {
flow: 'all',
},
plugins: [[stylexPlugin, opts]],
plugins: [[stylexPlugin, { runtimeInjection: true, ...opts }]],
}).code;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function transform(source, opts = {}) {
parserOpts: {
flow: 'all',
},
plugins: [jsx, [stylexPlugin, opts]],
plugins: [jsx, [stylexPlugin, { ...opts, runtimeInjection: true }]],
}).code;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function transform(source, opts = {}) {
parserOpts: {
flow: 'all',
},
plugins: [[stylexPlugin, opts]],
plugins: [[stylexPlugin, { runtimeInjection: true, ...opts }]],
}).code;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const stylexPlugin = require('../src/index');
function transform(source, opts = {}) {
const options = {
filename: opts.filename,
plugins: [[stylexPlugin, opts]],
plugins: [[stylexPlugin, { ...opts, runtimeInjection: true }]],
};
const result = transformSync(source, options);
return result;
Expand Down
7 changes: 4 additions & 3 deletions packages/babel-plugin/src/utils/state-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ export default class StateManager {
...options,
dev: !!(options: $FlowFixMe).dev,
test: !!(options: $FlowFixMe).test,
stylexSheetName: (options: $FlowFixMe).stylexSheetName ?? undefined,
runtimeInjection:
(options: $FlowFixMe).runtimeInjection ?? !!(options: $FlowFixMe).dev,
classNamePrefix: (options: $FlowFixMe).classNamePrefix ?? 'x',
importSources: (options: $FlowFixMe).importSources ?? [name, 'stylex'],
definedStylexCSSVariables:
Expand Down Expand Up @@ -117,8 +118,8 @@ export default class StateManager {
return this._state.file.metadata;
}

get stylexSheetName(): string | void {
return this.options.stylexSheetName ?? undefined;
get runtimeInjection(): boolean {
return !!this.options.runtimeInjection;
}

get isDev(): boolean {
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-plugin/src/visitors/stylex-create-theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export default function transformStyleXCreateTheme(
// This should be a transformed variables object
callExpressionPath.replaceWith(convertObjectToAST(overridesObj));

if (state.isDev || state.stylexSheetName == null) {
if (state.runtimeInjection) {
// We know that the top level parent path is an variable declarator
const statementPath: ?NodePath<> = variableDeclaratorPath.parentPath;

Expand Down
2 changes: 1 addition & 1 deletion packages/babel-plugin/src/visitors/stylex-create/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export default function transformStyleXCreate(
if (Object.keys(injectedStyles).length === 0) {
return;
}
if (state.isDev || state.stylexSheetName == null) {
if (state.runtimeInjection) {
const statementPath = findNearestStatementAncestor(path);
const stylexName = getStylexDefaultImport(path, state);

Expand Down
2 changes: 1 addition & 1 deletion packages/babel-plugin/src/visitors/stylex-define-vars.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export default function transformStyleXDefineVars(
// This should be a transformed variables object
callExpressionPath.replaceWith(convertObjectToAST(variablesObj));

if (state.isDev || state.stylexSheetName == null) {
if (state.runtimeInjection) {
// We know that the top level parent path is an export named declaration
const maybeStatementPath: ?NodePath<> =
variableDeclaratorPath.parentPath.parentPath;
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-plugin/src/visitors/stylex-keyframes.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export default function transformStyleXKeyframes(
const { ltr, priority, rtl } = injectedStyle;

if (
(state.isDev || state.stylexSheetName == null) &&
state.runtimeInjection &&
pathUtils.isVariableDeclaration(path.parentPath)
) {
// We know that the parent path is a variable declaration
Expand Down
Loading

0 comments on commit dc3cca7

Please sign in to comment.