Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into update-github-workflo…
Browse files Browse the repository at this point in the history
…ws--intuitive-american-coonhound-4ae67ebb97
  • Loading branch information
romainmenke committed Feb 29, 2024
2 parents 5c01504 + 2c7541d commit fd0941e
Show file tree
Hide file tree
Showing 43 changed files with 4,759 additions and 6,379 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ polyfills/__dist/**
# We do not ignore the config.json, detect.js or tests.js
# because we do control their implementation.

test/coverage/**

polyfills/ArrayBuffer/polyfill.js
polyfills/atob/polyfill.js
polyfills/AudioContext/polyfill.js
Expand Down
11 changes: 10 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,19 @@ module.exports = {
SharedArrayBuffer: "readonly"
},
parserOptions: {
ecmaVersion: 2018
ecmaVersion: 2018,
allowReserved: false
},
rules: {
"unicorn/prefer-optional-catch-binding": "off",
"unicorn/prefer-ternary": "off",
"unicorn/prefer-module": "off",
"unicorn/prefer-string-replace-all": "off",
"unicorn/text-encoding-identifier-case": "off",
"unicorn/no-typeof-undefined": "off",
"unicorn/numeric-separators-style": "off",
"unicorn/switch-case-braces": "off",
"unicorn/prefer-at": "off",
"unicorn/prefer-top-level-await": "off",
}
};
23 changes: 2 additions & 21 deletions .github/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,25 +145,6 @@ Start the build watcher :

Or build once using `npm run build`.

### Testing locally

You can run the tests locally in a headless browser, e.g. if you don't have BrowserStack
credentials, are working offline, or want to run the tests in an isolated environment
without access to your host machine.

To run the `URL` tests once :

```
$ npm run test-polyfills -- --features=URL --browsers=FirefoxHeadless --singleRun=true
...
Finished in 0.019 secs
SUMMARY:
✔ 53 tests completed
```

### Testing with BrowserStack

After a file change you will see :

Expand All @@ -185,14 +166,14 @@ Only you will have access to these credentials.

1. visit `Settings` > `Actions` on github and make sure actions are allowed to run.
2. visit `Settings` > `Secrets` on github and add credentials for Browserstack.
3. visit `Actions` on github and disable all workflows except `Test From Fork`.
3. visit `Actions` on github and disable all workflows except `Test Polyfills`.

These credentials are required :
- `BROWSERSTACK_ACCESS_KEY`
- `BROWSERSTACK_USERNAME`

When you want to verify your changes just push to your fork and visit `Actions`.
Select `Test From Fork` and click `Run workflow` selecting the branch where you pushed your changes.
Select `Test Polyfills` and click `Run workflow` selecting the branch where you pushed your changes.

Notes :
- tests can take a long time to run (>1h for a full run)
Expand Down
49 changes: 2 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,48 +82,6 @@ Create a polyfill bundle.

Returns a polyfill bundle as either a utf-8 ReadStream or as a Promise of a utf-8 String.

## AWS Lambda

To use this package in an AWS Lambda function, you need to include the distribution Polyfills located in `./node_modules/@mrhenry/polyfill-library/polyfills/__dist` in the root directory of your Lambda. In AWS, Lambdas are executed in the `/var/task/...` directory. Therefore, during execution, the directory where the polyfills will be located will be `/var/task/@mrhenry/polyfill-library/__dist`.

### Example of a script to copy files

The following snippet will allow us to copy the polyfills to our already compiled Lambda. To do this, we will first install the necessary dependencies.

```bash
yarn add -D make-dir fs-extra
```

Once the dependencies are installed, we will create the file with the script at `/scripts/polyfills-serverless.mjs` and replace `YOUR_BUNDELED_LAMBDA_DIRECTORY` with the directory that contains our packaged Lambda.

In the example, we will use the directory `./.serverless_nextjs/api-lambda`, which is the one used when using Serverless Next.js.

```js
import { copySync } from 'fs-extra/esm';
import makeDir from 'make-dir';

const DIR_POLYFILLS = './node_modules/@mrhenry/polyfill-library/polyfills/__dist';
// const DIR_SERVERLESS = 'YOUR_BUNDELED_LAMBDA_DIRECTORY/polyfills/__dist';
const DIR_SERVERLESS = './.serverless_nextjs/api-lambda/polyfills/__dist';

const paths = await makeDir(DIR_SERVERLESS);
console.log(`The directory ${paths} is created successfully.`);

try {
console.log('Copying polyfills to serverless directory...');
copySync(DIR_POLYFILLS, DIR_SERVERLESS, { overwrite: false });
console.log('Polyfills copied successfully!');
} catch (err) {
console.error(err);
}
```

To execute the script, you will need to run the following command:

```bash
node ./scripts/polyfills-serverless.mjs
```

## Contributing

Development of @mrhenry/polyfill-library happens on GitHub. Read below to learn how you can take part in contributing.
Expand All @@ -133,11 +91,8 @@ Development of @mrhenry/polyfill-library happens on GitHub. Read below to learn
Read our [contributing guide][contributing-guide] to learn about our development process, how to propose bugfixes and improvements, and how to build and test your changes.

```
# To test on BrowserStack you will need to have a BrowserStack account
# We test pull-requests using BrowserStack
npm run test-all-polyfills # Run the tests for all polyfills using BrowserStack
npm run test-polyfills -- --features=Array.from # Run the tests for Array.from
npm run test-polyfills -- --features=Array.from --browserstack # Run the tests for Array.from using BrowserStack
npm run install
npm run watch
```

### License
Expand Down
62 changes: 0 additions & 62 deletions karma-polyfill-library-plugin.js

This file was deleted.

176 changes: 0 additions & 176 deletions karma.conf.js

This file was deleted.

Loading

0 comments on commit fd0941e

Please sign in to comment.