From 93db87cfc473bc23891a30c37629d052941b728a Mon Sep 17 00:00:00 2001 From: Dennis Schaller Date: Mon, 11 Nov 2019 16:49:33 +0100 Subject: [PATCH] feat(react): add options to opt out of calling applyPolyfills/defineCustomElements by default chore(): update to current @stencil/core version chore(react): update to current @types/jest and jest version --- package-lock.json | 14 ++++----- package.json | 2 +- packages/react-output-target/package.json | 4 +-- .../react-output-target/src/output-react.ts | 30 +++++++++++++------ packages/react-output-target/src/types.ts | 2 ++ 5 files changed, 33 insertions(+), 19 deletions(-) diff --git a/package-lock.json b/package-lock.json index 9681a1a9..fcf3b0b5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -901,12 +901,12 @@ } }, "@stencil/core": { - "version": "1.0.0-beta.5", - "resolved": "https://registry.npmjs.org/@stencil/core/-/core-1.0.0-beta.5.tgz", - "integrity": "sha512-rJpH57nn+E6F84HastQ8RDuhq+j5LeUey3sVW192y5VCTmHbMUfiwVgtFIUo6+BDIXagAG01rbm7WHCMTSGdSw==", + "version": "1.7.5", + "resolved": "https://javabuild.intranet.commerzbank.com/nexus/repository/npm-all/@stencil/core/-/core-1.7.5.tgz", + "integrity": "sha512-VlXKeN/FAqwaZ5yVWOZB+3biwL6TBZHEN8iWJIHnM7AskKCBDSSHXktPjBOCAuO2/kB82je712GrIpqRnMJGHA==", "dev": true, "requires": { - "typescript": "3.4.5" + "typescript": "3.6.3" } }, "JSONStream": { @@ -5598,9 +5598,9 @@ "dev": true }, "typescript": { - "version": "3.4.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.4.5.tgz", - "integrity": "sha512-YycBxUb49UUhdNMU5aJ7z5Ej2XGmaIBL0x34vZ82fn3hGvD+bgrMrVDpatgz2f7YxUMJxMkbWxJZeAvDxVe7Vw==", + "version": "3.6.3", + "resolved": "https://javabuild.intranet.commerzbank.com/nexus/repository/npm-all/typescript/-/typescript-3.6.3.tgz", + "integrity": "sha512-N7bceJL1CtRQ2RiG0AQME13ksR7DiuQh/QehubYcghzv20tnh+MQnQIuJddTmsbqYj+dztchykemz0zFzlvdQw==", "dev": true }, "uglify-js": { diff --git a/package.json b/package.json index afca715c..0328b911 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "build": "lerna run build" }, "devDependencies": { - "@stencil/core": "^1.0.0-beta.5", + "@stencil/core": "^1.7.5", "lerna": "^3.13.1" } } diff --git a/packages/react-output-target/package.json b/packages/react-output-target/package.json index 6ea406ca..93d64709 100644 --- a/packages/react-output-target/package.json +++ b/packages/react-output-target/package.json @@ -34,10 +34,10 @@ "url": "https://github.com/ionic-team/stencil-ds-plugins/issues" }, "devDependencies": { - "@types/jest": "^24.0.11", + "@types/jest": "^24.0.22", "@types/react": "^16.7.0", "@types/react-dom": "^16.7.0", - "jest": "^24.5.0", + "jest": "^24.9.0", "np": "^5.0.2", "react": "^16.7.0", "react-dom": "^16.7.0", diff --git a/packages/react-output-target/src/output-react.ts b/packages/react-output-target/src/output-react.ts index 9736bca1..d0b2bda7 100644 --- a/packages/react-output-target/src/output-react.ts +++ b/packages/react-output-target/src/output-react.ts @@ -1,6 +1,6 @@ import path from 'path'; import { OutputTargetReact } from './types'; -import { dashToPascalCase, readPackageJson, relativeImport, sortBy, normalizePath } from './utils'; +import { dashToPascalCase, normalizePath, readPackageJson, relativeImport, sortBy } from './utils'; import { CompilerCtx, ComponentCompilerMeta, Config } from '@stencil/core/internal'; export async function reactProxyOutput( @@ -32,6 +32,7 @@ async function generateProxies( const distTypesDir = path.dirname(pkgData.types); const dtsFilePath = path.join(rootDir, distTypesDir, GENERATED_DTS); const componentsTypeFile = relativeImport(outputTarget.proxiesFile, dtsFilePath, '.d.ts'); + const { noAutoPolyfills, noAutoRegister } = outputTarget; const imports = `/* tslint:disable */ /* auto-generated react proxies */ @@ -41,14 +42,23 @@ import { createReactComponent } from './react-component-lib';\n`; ? `import { ${IMPORT_TYPES} } from '${normalizePath(componentsTypeFile)}';\n` : `import { ${IMPORT_TYPES} } from '${normalizePath(outputTarget.componentCorePackage)}';\n`; - const sourceImports = `import { ${REGISTER_CUSTOM_ELEMENTS}, ${APPLY_POLYFILLS} } from '${normalizePath( - path.join( - outputTarget.componentCorePackage || '', - outputTarget.loaderDir || DEFAULT_LOADER_DIR, - ), - )}';\n`; - - const registerCustomElements = `${APPLY_POLYFILLS}().then(() => { ${REGISTER_CUSTOM_ELEMENTS}(window); });`; + const sourceImports = !(noAutoPolyfills && noAutoRegister) + ? `import { ${[!noAutoRegister && REGISTER_CUSTOM_ELEMENTS, !noAutoPolyfills && APPLY_POLYFILLS] + .filter(Boolean) + .join(', ')} } from '${normalizePath( + path.join( + outputTarget.componentCorePackage || '', + outputTarget.loaderDir || DEFAULT_LOADER_DIR, + ), + )}';\n` + : ''; + + const registerCustomElements = [ + '', + `${APPLY_POLYFILLS}();`, + `${REGISTER_CUSTOM_ELEMENTS}(window);`, + `${APPLY_POLYFILLS}().then(() => { ${REGISTER_CUSTOM_ELEMENTS}(window); });`, + ][(+!noAutoRegister << 1) | +!noAutoPolyfills]; const final: string[] = [ imports, @@ -86,7 +96,9 @@ async function copyResources(config: Config, outputTarget: OutputTargetReact) { src: path.join(srcDirectory, '../react-component-lib/', rf), dest: path.join(destDirectory, rf), warn: false, + keepDirStructure: true, })), + config.srcDir || '', ); } diff --git a/packages/react-output-target/src/types.ts b/packages/react-output-target/src/types.ts index a7280b13..4968b5a0 100644 --- a/packages/react-output-target/src/types.ts +++ b/packages/react-output-target/src/types.ts @@ -1,6 +1,8 @@ export interface OutputTargetReact { componentCorePackage?: string; proxiesFile: string; + noAutoPolyfills?: boolean; + noAutoRegister?: boolean; excludeComponents?: string[]; loaderDir?: string; }