Skip to content

Commit

Permalink
current error is coming from @ember/test-helpers about class properties
Browse files Browse the repository at this point in the history
transform missing... *YET*, all my targets support class properties.....

Build Error (broccoli-persistent-filter:Babel > [Babel: @ember/test-helpers]) in @ember/test-helpers/-internal/debug-info.js

/NullVoxPopuli/ember-statechart-component/@ember/test-helpers/-internal/debug-info.js: Missing class properties transform.
  40 |
  41 | export class TestDebugInfo {
> 42 |   _summaryInfo = undefined;
     |   ^^^^^^^^^^^^^^^^^^^^^^^^^
  43 |
  44 |   constructor(settledState, debugInfo = getDebugInfo()) {
  45 |     this._settledState = settledState;
  • Loading branch information
NullVoxPopuli committed Nov 26, 2021
1 parent 79246f0 commit 0f1b995
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 277 deletions.
38 changes: 4 additions & 34 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
const {
_shouldCompileModules,
_shouldIncludeHelpers,
_shouldHandleTypeScript,
_getExtensions,
_parentName,
_shouldHighlightCode,
Expand Down Expand Up @@ -58,34 +57,7 @@ module.exports = {

let config = _config || this._getAddonOptions();

const customAddonConfig = config['ember-cli-babel'];
const shouldUseBabelConfigFile = customAddonConfig && customAddonConfig.useBabelConfig;

let options;

if (shouldUseBabelConfigFile) {
let babelConfig = babel.loadPartialConfig({
root: this.parent.root,
rootMode: 'root',
envName: process.env.EMBER_ENV || process.env.BABEL_ENV || process.env.NODE_ENV || "development",
});

if (babelConfig.config === undefined) {
// should contain the file that we used for the config,
// if it is undefined then we didn't find any config and
// should error

throw new Error(
"Missing babel config file in the project root. Please double check if the babel config file exists or turn off the `useBabelConfig` option in your ember-cli-build.js file."
);
}

// If the babel config file is found, then pass the path into the options for the transpiler
// parse and leverage the same.
options = { configFile: babelConfig.config };
} else {
options = getBabelOptions(config, this);
}
let options = getBabelOptions(config, this);

if (resultType === 'babel') {
return options;
Expand Down Expand Up @@ -160,11 +132,9 @@ module.exports = {
let BabelTranspiler = require('broccoli-babel-transpiler');
let transpilationInput = postDebugTree;

if (_shouldHandleTypeScript(config, this.parent, this.project)) {
let Funnel = require('broccoli-funnel');
let inputWithoutDeclarations = new Funnel(transpilationInput, { exclude: ['**/*.d.ts'] });
transpilationInput = this._debugTree(inputWithoutDeclarations, `${description}:filtered-input`);
}
let Funnel = require('broccoli-funnel');
let inputWithoutDeclarations = new Funnel(transpilationInput, { exclude: ['**/*.d.ts'] });
transpilationInput = this._debugTree(inputWithoutDeclarations, `${description}:filtered-input`);

output = new BabelTranspiler(transpilationInput, options);
}
Expand Down
183 changes: 2 additions & 181 deletions lib/babel-options-util.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const VersionChecker = require("ember-cli-version-checker");
const resolvePackagePath = require("resolve-package-path");
const clone = require("clone");
const semver = require("semver");

Expand Down Expand Up @@ -296,117 +295,6 @@ function _getHelperVersion(project) {
return APP_BABEL_RUNTIME_VERSION.get(project);
}

function _buildClassFeaturePluginConstraints(constraints, config, parent, project) {
// With versions of ember-cli-typescript < 4.0, class feature plugins like
// @babel/plugin-proposal-class-properties were run before the TS transform.
if (!_shouldHandleTypeScript(config, parent, project)) {
constraints.before = constraints.before || [];
constraints.before.push("@babel/plugin-transform-typescript");
}

return constraints;
}

function _addDecoratorPlugins(plugins, options, config, parent, project) {
const { hasPlugin, addPlugin } = require("ember-cli-babel-plugin-helpers");

if (hasPlugin(plugins, "@babel/plugin-proposal-decorators")) {
if (parent === project) {
project.ui.writeWarnLine(
`${_parentName(
parent
)} has added the decorators plugin to its build, but ember-cli-babel provides these by default now! You can remove the transforms, or the addon that provided them, such as @ember-decorators/babel-transforms. Ember supports the stage 1 decorator spec and transforms, so if you were using stage 2, you'll need to ensure that your decorators are compatible, or convert them to stage 1.`
);
}
} else {
addPlugin(
plugins,
[require.resolve("@babel/plugin-proposal-decorators"), { legacy: true }],
_buildClassFeaturePluginConstraints(
{
before: ["@babel/plugin-proposal-class-properties"],
},
config,
parent,
project
)
);
}

if (hasPlugin(plugins, "@babel/plugin-proposal-class-properties")) {
if (parent === project) {
project.ui.writeWarnLine(
`${_parentName(
parent
)} has added the class-properties plugin to its build, but ember-cli-babel provides these by default now! You can remove the transforms, or the addon that provided them, such as @ember-decorators/babel-transforms.`
);
}
} else {
let pluginsToAdd = [plugins]

pluginsToAdd.push(
_buildClassFeaturePluginConstraints(
{
after: ["@babel/plugin-proposal-decorators"],
},
config,
parent,
project
)
)
addPlugin(...pluginsToAdd);
}

if (hasPlugin(plugins, "babel-plugin-filter-imports")) {
let checker = new VersionChecker(parent).for(
"babel-plugin-filter-imports",
"npm"
);

if (checker.lt("3.0.0")) {
addPlugin(
plugins,
require.resolve("./dedupe-internal-decorators-plugin"),
{
after: ["babel-plugin-filter-imports"],
}
);
}
}

return plugins;
}

function _addTypeScriptPlugin(plugins, parent, project) {
const { hasPlugin, addPlugin } = require("ember-cli-babel-plugin-helpers");

if (hasPlugin(plugins, "@babel/plugin-transform-typescript")) {
if (parent === project) {
project.ui.writeWarnLine(
`${_parentName(
parent
)} has added the TypeScript transform plugin to its build, but ember-cli-babel provides this by default now when ember-cli-typescript >= 4.0 is installed! You can remove the transform, or the addon that provided it.`
);
}
} else {
addPlugin(
plugins,
[
require.resolve("@babel/plugin-transform-typescript"),
{ allowDeclareFields: true },
],
{
before: [
"@babel/plugin-proposal-class-properties",
"@babel/plugin-proposal-private-methods",
"@babel/plugin-proposal-decorators",
],
}
);
}
return plugins;
}

function _parentName(parent) {
let parentName;

Expand All @@ -421,13 +309,8 @@ function _parentName(parent) {
return parentName;
}

function _getExtensions(config, parent, project) {
let shouldHandleTypeScript = _shouldHandleTypeScript(config, parent, project);
let emberCLIBabelConfig = config["ember-cli-babel"] || {};
return (
emberCLIBabelConfig.extensions ||
(shouldHandleTypeScript ? ["js", "ts"] : ["js"])
);
function _getExtensions() {
return ['js', 'ts'];
}

function _shouldIncludeDecoratorPlugins(config) {
Expand All @@ -436,65 +319,6 @@ function _shouldIncludeDecoratorPlugins(config) {
return customOptions.disableDecoratorTransforms !== true;
}

/**
* Returns whether we should handle TypeScript (based on the existence of
* `ember-cli-typescript` as a depenency). It's worth noting that we parse
* the `package.json` deps/devDeps directly (rather than using `addons` on
* the parent) because it's possible for `ember-cli-typescript` not to exist
* on the addons array, even if it is a dependency.
*
* Some more context:
*
* `ember-cli-typescript` returns a stable cache key so its possible for it to
* be deduped as part of `ember-engines`. The reason this is important is because
* `ember-engines` dedupe is _stateful_ so it's possible for `ember-cli-typescript`
* to not be part of the addons array when `ember-cli-babel` is running.
*
* For more info on `ember-engines` dedupe logic:
* https://github.com/ember-engines/ember-engines/blob/master/packages/ember-engines/lib/utils/deeply-non-duplicated-addon.js#L35
*
* @name _shouldHandleTypeScript
* @returns {boolean}
*/
function _shouldHandleTypeScript(config, parent, project) {
let emberCLIBabelConfig = config["ember-cli-babel"] || {};

if (typeof emberCLIBabelConfig.enableTypeScriptTransform === "boolean") {
return emberCLIBabelConfig.enableTypeScriptTransform;
}

let pkg = parent.pkg;

if (!pkg) {
return false;
}

let dependencies;

// consider `dependencies` and `devDependencies` if the parent is the project
// (`ember-cli` uses both in this case), otherwise only care about `dependencies`
if (parent === project) {
dependencies = Object.assign({}, pkg.dependencies, pkg.devDependencies);
} else {
dependencies = pkg.dependencies || {};
}

let tsDependency = dependencies["ember-cli-typescript"];

if (tsDependency !== undefined) {
let tsPkgPath = resolvePackagePath("ember-cli-typescript", parent.root);

if (tsPkgPath === null) {
return false;
}

let tsPkg = require(tsPkgPath);
return semver.gte(tsPkg.version, "4.0.0-alpha.1");
}

return false;
}

function _getAddonProvidedConfig(addonOptions) {
let options = clone(addonOptions.babel || {});

Expand Down Expand Up @@ -565,12 +389,9 @@ function _shouldIncludeHelpers(options, appInstance) {
}

module.exports = {
_addDecoratorPlugins,
_addTypeScriptPlugin,
_getAddonProvidedConfig,
_shouldCompileModules,
_shouldIncludeHelpers,
_shouldHandleTypeScript,
_shouldIncludeDecoratorPlugins,
_getExtensions,
_parentName,
Expand Down
77 changes: 29 additions & 48 deletions lib/get-babel-options.js
Original file line number Diff line number Diff line change
@@ -1,73 +1,54 @@
const {
_addDecoratorPlugins,
_addTypeScriptPlugin,
_getAddonProvidedConfig,
_shouldCompileModules,
_shouldIncludeHelpers,
_shouldHandleTypeScript,
_shouldIncludeDecoratorPlugins,
_getHelpersPlugin,
_getDebugMacroPlugins,
_getEmberModulesAPIPolyfill,
_getEmberDataPackagesPolyfill,
_getModulesPlugin,
_getPresetEnv,
} = require("./babel-options-util");

module.exports = function getBabelOptions(config, appInstance) {
let { parent, project } = appInstance;
let addonProvidedConfig = _getAddonProvidedConfig(config);
let shouldIncludeHelpers = _shouldIncludeHelpers(config, appInstance);
let shouldHandleTypeScript = _shouldHandleTypeScript(config, parent, project);
let shouldIncludeDecoratorPlugins = _shouldIncludeDecoratorPlugins(config);

let emberCLIBabelConfig = config["ember-cli-babel"];
let shouldRunPresetEnv = true;

if (emberCLIBabelConfig) {
shouldRunPresetEnv = !emberCLIBabelConfig.disablePresetEnv;
}

let options = {};

let userPlugins = addonProvidedConfig.plugins;
let userPostTransformPlugins = addonProvidedConfig.postTransformPlugins;

if (shouldHandleTypeScript) {
userPlugins = _addTypeScriptPlugin(userPlugins.slice(), parent, project);
}

if (appInstance.isPluginRequired("@babel/plugin-proposal-class-properties")) {
userPlugins = [...userPlugins, [
require.resolve("@babel/plugin-proposal-class-properties"),
{ loose: addonProvidedConfig.options.loose || false },
]]
}

if (shouldIncludeDecoratorPlugins) {
userPlugins = _addDecoratorPlugins(
userPlugins.slice(),
addonProvidedConfig.options,
config,
parent,
project
);
}

options.plugins = []
.concat(
let babelOptions = {
presets: [require.resolve('@babel/preset-env', {
loose: true,
exclude: [
'@babel/plugin-transform-classes',
'@babel/plugin-proposal-private-methods',
'@babel/plugin-proposal-class-properties',
]
})],
plugins: [].concat(
shouldIncludeHelpers && _getHelpersPlugin(project),
userPlugins,
addonProvidedConfig.plugins,
[
[require.resolve('@babel/plugin-transform-typescript'), { allowDeclareFields: true }],
[require.resolve('@babel/plugin-proposal-decorators'), { legacy: true }],
],
_getDebugMacroPlugins(config, project),
_getEmberModulesAPIPolyfill(config, parent, project),
_getEmberDataPackagesPolyfill(config, parent),
_shouldCompileModules(config, project) && _getModulesPlugin(),
(_shouldCompileModules(config, project) && _getModulesPlugin()),
userPostTransformPlugins
).filter(Boolean);
).filter(Boolean).filter((item) => {
if (!Array.isArray(item)) return true;

// Scrub invalid plugin configs, because we rely on preset-env now
if (item[0] === '@babel/plugin-proposal-private-methods') return false;

return true;
}),
};

console.log('|||||||||||||||||||||||||||||||||')
console.log(babelOptions);//JSON.stringify(babelOptions, null, 2));

options.presets = [
shouldRunPresetEnv && _getPresetEnv(addonProvidedConfig, project),
].filter(Boolean);
return babelOptions;

return options;
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"@babel/plugin-transform-typescript": "^7.13.0",
"@babel/polyfill": "^7.11.5",
"@babel/preset-env": "^7.12.0",
"@babel/runtime": "7.12.18",
"@babel/runtime": "^7.12.18",
"amd-name-resolver": "^1.3.1",
"babel-plugin-debug-macros": "^0.3.4",
"babel-plugin-ember-data-packages-polyfill": "^0.1.2",
Expand Down
Loading

0 comments on commit 0f1b995

Please sign in to comment.