Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix regeneratorRuntime is not defined in @magic-sdk/provider #215

Merged
merged 4 commits into from
Sep 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/@magic-sdk/provider/src/index.cjs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* istanbul ignore file */

import 'regenerator-runtime/runtime';

export * from './index';
5 changes: 5 additions & 0 deletions packages/@magic-sdk/provider/src/index.es.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* istanbul ignore file */

import 'regenerator-runtime/runtime';

export * from './index';
5 changes: 5 additions & 0 deletions packages/magic-sdk/src/index.cjs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* istanbul ignore file */

import 'regenerator-runtime/runtime';

export * from './index';
5 changes: 5 additions & 0 deletions packages/magic-sdk/src/index.es.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* istanbul ignore file */

import 'regenerator-runtime/runtime';

export * from './index';
2 changes: 0 additions & 2 deletions packages/magic-sdk/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/* istanbul ignore file */

import 'regenerator-runtime/runtime';

import { SDKBase, createSDK } from '@magic-sdk/provider';
import localForage from 'localforage';
import * as memoryDriver from 'localforage-driver-memory';
Expand Down
3 changes: 1 addition & 2 deletions scripts/bin/wsrun/build-package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ async function modern() {
async function cdn() {
const pkgJson = require(`${process.cwd()}/package.json`);
await build({
source: 'src/index.cdn.ts',
format: 'iife',
format: 'cdn',
target: pkgJson.target,
output: pkgJson['umd:main'],
name: pkgJson.umdGlobal,
Expand Down
30 changes: 26 additions & 4 deletions scripts/utils/microbundle.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import execa from 'execa';
import path from 'path';
import { environment } from './environment';
import { existsAsync } from './exists-async';

type MicrobundleFormat = 'modern' | 'es' | 'cjs' | 'umd' | 'iife';
type MicrobundleFormat = 'modern' | 'es' | 'cjs' | 'cdn';

export async function build(
options: {
source?: string;
target?: string;
format?: MicrobundleFormat;
output?: string;
Expand All @@ -17,11 +18,11 @@ export async function build(
if (options.output) {
/* eslint-disable prettier/prettier */
const args = [
'build', options.source ?? 'src/index.ts',
'build', await getFormatSpecificEntrypoint(options.format),
'--tsconfig', 'tsconfig.json',
'--target', options.target ?? 'web',
'--jsx', 'React.createElement',
'--format', options.format ?? 'cjs',
'--format', getFormatForMicrobundle(options.format),
'--sourcemap', options.sourcemap ? 'true' : 'false',
options.external && '--external', options.external,
'--output', options.output,
Expand All @@ -33,3 +34,24 @@ export async function build(
await execa('microbundle', args as any, { stdio: 'inherit' });
}
}

async function getFormatSpecificEntrypoint(format?: MicrobundleFormat) {
if (await existsAsync(path.resolve(process.cwd(), `./src/index.${format}.ts`))) {
return `src/index.${format}.ts`;
}

return 'src/index.ts';
}

function getFormatForMicrobundle(format?: MicrobundleFormat) {
switch (format) {
case 'cdn':
return 'iife';

case 'modern':
case 'es':
case 'cjs':
default:
return format ?? 'cjs';
}
}
24 changes: 12 additions & 12 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4118,24 +4118,24 @@ __metadata:
languageName: node
linkType: hard

"@magic-sdk/commons@^2.0.3, @magic-sdk/commons@workspace:packages/@magic-sdk/commons":
"@magic-sdk/commons@^2.0.4, @magic-sdk/commons@workspace:packages/@magic-sdk/commons":
version: 0.0.0-use.local
resolution: "@magic-sdk/commons@workspace:packages/@magic-sdk/commons"
dependencies:
"@magic-sdk/provider": ^6.0.3
"@magic-sdk/types": ^5.0.1
"@magic-sdk/provider": ^6.0.4
"@magic-sdk/types": ^5.0.2
peerDependencies:
"@magic-sdk/provider": ">=4.3.0"
"@magic-sdk/types": ">=3.1.1"
languageName: unknown
linkType: soft

"@magic-sdk/provider@^6.0.3, @magic-sdk/provider@workspace:packages/@magic-sdk/provider":
"@magic-sdk/provider@^6.0.4, @magic-sdk/provider@workspace:packages/@magic-sdk/provider":
version: 0.0.0-use.local
resolution: "@magic-sdk/provider@workspace:packages/@magic-sdk/provider"
dependencies:
"@babel/plugin-transform-modules-commonjs": ^7.9.6
"@magic-sdk/types": ^5.0.1
"@magic-sdk/types": ^5.0.2
"@peculiar/webcrypto": ^1.1.7
eventemitter3: ^4.0.4
localforage: ^1.7.4
Expand All @@ -4155,9 +4155,9 @@ __metadata:
"@babel/core": ^7.15.0
"@babel/plugin-transform-flow-strip-types": ^7.14.5
"@babel/runtime": ~7.10.4
"@magic-sdk/commons": ^2.0.3
"@magic-sdk/provider": ^6.0.3
"@magic-sdk/types": ^5.0.1
"@magic-sdk/commons": ^2.0.4
"@magic-sdk/provider": ^6.0.4
"@magic-sdk/types": ^5.0.2
"@react-native-async-storage/async-storage": ^1.15.5
"@types/lodash": ^4.14.158
buffer: ~5.6.0
Expand All @@ -4178,7 +4178,7 @@ __metadata:
languageName: unknown
linkType: soft

"@magic-sdk/types@^5.0.1, @magic-sdk/types@workspace:packages/@magic-sdk/types":
"@magic-sdk/types@^5.0.2, @magic-sdk/types@workspace:packages/@magic-sdk/types":
version: 0.0.0-use.local
resolution: "@magic-sdk/types@workspace:packages/@magic-sdk/types"
languageName: unknown
Expand Down Expand Up @@ -13746,9 +13746,9 @@ fsevents@^1.2.7:
"@babel/core": ^7.9.6
"@babel/plugin-proposal-optional-chaining": ^7.9.0
"@babel/runtime": ^7.9.6
"@magic-sdk/commons": ^2.0.3
"@magic-sdk/provider": ^6.0.3
"@magic-sdk/types": ^5.0.1
"@magic-sdk/commons": ^2.0.4
"@magic-sdk/provider": ^6.0.4
"@magic-sdk/types": ^5.0.2
localforage: ^1.7.4
localforage-driver-memory: ^1.0.5
languageName: unknown
Expand Down