UNPKG

@jscutlery/swc-angular

Version:
115 lines (108 loc) 3.92 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var node_path = require('node:path'); var core = require('@swc/core'); var node_fs = require('node:fs'); function _extends() { _extends = Object.assign || function assign(target) { for(var i = 1; i < arguments.length; i++){ var source = arguments[i]; for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key]; } return target; }; return _extends.apply(this, arguments); } class FileSystem { readJsonFile(path) { const content = node_fs.readFileSync(path, 'utf-8'); return JSON.parse(content); } } const fileSystem = new FileSystem(); assertCompatibleSwcCoreVersion(core.version); function swcAngularPreset(options = {}) { return { jsc: { parser: { syntax: 'typescript', decorators: true, dynamicImport: true }, transform: { legacyDecorator: true, decoratorMetadata: true, useDefineForClassFields: options.useDefineForClassFields }, experimental: { plugins: [ [ '@jscutlery/swc-angular-plugin', { importStyles: options.importStyles, styleInlineSuffix: options.styleInlineSuffix, templateRawSuffix: options.templateRawSuffix } ] ] } }, env: { targets: [ 'last 2 chrome versions' ], include: [ 'transform-async-to-generator' ] }, swcrc: false }; } function swcAngularJestTransformer(options = {}) { return [ '@swc/jest', swcAngularPreset(options) ]; } function swcAngularVitePreset(options = {}) { return swcAngularPreset(_extends({ importStyles: true, styleInlineSuffix: true, templateRawSuffix: true }, options)); } function swcAngularUnpluginOptions(options = {}) { return _extends({}, swcAngularVitePreset(options), { /* Since we are using SWC's env option, we need to disable the tsconfigFile option. * Otherwise `unpluggin-swc` will try to use the target from the tsconfig's `compilerOptions`, * and make SWC produce the following error: "`env` and `jsc.target` cannot be used together". * * We could have added this extra option to `swcAngularVitePreset`, but forwarding any extra option * to SWC will make SWC's configuration parser fail. * * Cf. https://github.com/unplugin/unplugin-swc/issues/137 */ tsconfigFile: false }); } /** * @deprecated Use {@link swcAngularVitePreset}, {@link swcAngularJestTransformer} or {@link swcAngularPreset} instead. */ var index = swcAngularPreset(); function assertCompatibleSwcCoreVersion(version) { /* Fallback to reading version from package.json when not exported. * This happens on Stackblitz. */ if (version == undefined) { const packageJsonPath = node_path.join(node_path.dirname(require.resolve('@swc/core')), 'package.json'); version = fileSystem.readJsonFile(packageJsonPath).version; } if (!version.startsWith('1.10.')) { console.error(` @swc/core version ${version} is incompatible with @jscutlery/swc-angular. Please use @swc/core version 1.10.x > npm add -D @swc/core@~1.10.0 `); process.exit(1); } } exports.default = index; exports.swcAngularJestTransformer = swcAngularJestTransformer; exports.swcAngularPreset = swcAngularPreset; exports.swcAngularUnpluginOptions = swcAngularUnpluginOptions; exports.swcAngularVitePreset = swcAngularVitePreset;