Skip to content

Commit

Permalink
Merge branch 'master' into plugin-sass
Browse files Browse the repository at this point in the history
  • Loading branch information
FredKSchott authored Oct 6, 2020
2 parents 70e5959 + 04bed2b commit 12f303d
Show file tree
Hide file tree
Showing 43 changed files with 489 additions and 351 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Lint Code

on:
push:
branches:
- master
pull_request:

env:
node_version: 14

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2.3.2
- name: Use Node.js ${{ env.node_version }}
uses: actions/setup-node@v2.1.1
with:
node-version: ${{ env.node_version }}
- name: lint
run: |
yarn --ignore-engines
yarn build
yarn lint
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ For starter apps and templates, see [create-snowpack-app](./create-snowpack-app)
### Dev Environment

- [@snowpack/plugin-dotenv](./plugins/plugin-dotenv)
- [@snowpack/plugin-typescript](./plugins/plugin-typescript)

### Build

Expand All @@ -50,10 +51,10 @@ For starter apps and templates, see [create-snowpack-app](./create-snowpack-app)

### Bundle

- [@snowpack/plugin-parcel](./plugins/plugin-parcel)
- [@snowpack/plugin-webpack](./plugins/plugin-webpack)
- [@snowpack/plugin-parcel](./plugins/plugin-parcel)

### Advanced Plugins
### Utility Plugins

- [@snowpack/plugin-build-script](./plugins/plugin-build-script)
- [@snowpack/plugin-run-script](./plugins/plugin-run-script)
Expand Down
1 change: 1 addition & 0 deletions create-snowpack-app/app-scripts-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"@babel/preset-typescript": "^7.10.4",
"@snowpack/plugin-babel": "^2.1.2",
"@snowpack/plugin-dotenv": "^2.0.3",
"@snowpack/plugin-typescript": "^1.0.0",
"@snowpack/plugin-react-refresh": "^2.3.1",
"babel-jest": "^26.2.2",
"babel-preset-react-app": "^9.1.2",
Expand Down
2 changes: 1 addition & 1 deletion create-snowpack-app/app-scripts-react/snowpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = {
'@snowpack/plugin-react-refresh',
'@snowpack/plugin-babel',
'@snowpack/plugin-dotenv',
...(isTS ? [['@snowpack/plugin-run-script', {cmd: 'tsc --noEmit', watch: '$1 --watch'}]] : []),
...(isTS ? ['@snowpack/plugin-typescript'] : []),
],
devOptions: {},
installOptions: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
},
"devDependencies": {
"@snowpack/plugin-run-script": "^2.1.4",
"@snowpack/plugin-typescript": "^1.0.0",
"@types/canvas-confetti": "^1.0.0",
"@types/snowpack-env": "^2.3.0",
"prettier": "^2.0.5",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
"src": "/_dist_"
},
"plugins": [
[
"@snowpack/plugin-run-script",
{ "cmd": "tsc --noEmit", "watch": "$1 --watch" }
]
"@snowpack/plugin-typescript"
],
"installOptions": {
"installTypes": true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"@snowpack/plugin-babel": "^2.1.2",
"@snowpack/plugin-dotenv": "^2.0.3",
"@snowpack/plugin-run-script": "^2.1.4",
"@snowpack/plugin-typescript": "^1.0.0",
"@types/snowpack-env": "^2.3.0",
"prettier": "^2.0.5",
"snowpack": "^2.13.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ module.exports = {
plugins: [
'@snowpack/plugin-babel',
'@snowpack/plugin-dotenv',
[
'@snowpack/plugin-run-script',
{ cmd: 'tsc --noEmit', watch: '$1 --watch' },
],
"@snowpack/plugin-typescript"
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"@snowpack/app-scripts-react": "^1.12.1",
"@snowpack/plugin-dotenv": "^2.0.3",
"@snowpack/plugin-react-refresh": "^2.3.1",
"@snowpack/plugin-typescript": "^1.0.0",
"@testing-library/jest-dom": "^5.5.0",
"@testing-library/react": "^10.0.3",
"@types/react": "^16.9.49",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ module.exports = {
plugins: [
'@snowpack/plugin-react-refresh',
'@snowpack/plugin-dotenv',
['@snowpack/plugin-run-script', {cmd: 'tsc --noEmit', watch: '$1 --watch'}],
"@snowpack/plugin-typescript"
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"@snowpack/plugin-dotenv": "^2.0.3",
"@snowpack/plugin-run-script": "^2.1.4",
"@snowpack/plugin-svelte": "^2.1.1",
"@snowpack/plugin-typescript": "^1.0.0",
"@testing-library/jest-dom": "^5.5.0",
"@testing-library/svelte": "^3.0.0",
"@tsconfig/svelte": "^1.0.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ module.exports = {
plugins: [
'@snowpack/plugin-svelte',
'@snowpack/plugin-dotenv',
"@snowpack/plugin-typescript",
[
'@snowpack/plugin-run-script',
{cmd: 'svelte-check --output human', watch: '$1 --watch', output: 'stream'},
],
['@snowpack/plugin-run-script', {cmd: 'tsc --noEmit', watch: '$1 --watch'}],
],
};
2 changes: 1 addition & 1 deletion docs/docs/07-plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ This plugin allows you to connect any CLI into your build process. Just give it
// [npm install @snowpack/plugin-run-script]
{
"plugins": [
["@snowpack/plugin-run-script", { "cmd": "tsc --noEmit", "watch": "$1 --watch"}]
["@snowpack/plugin-run-script", { "cmd": "eleventy", "watch": "$1 --watch" }]
],
}
```
Expand Down
11 changes: 3 additions & 8 deletions docs/docs/08-guides.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,13 @@ Snowpack has built-in support to handle `.jsx` & `.tsx` source files in your app

### TypeScript

Snowpack has built-in support to handle `.ts` & `.tsx` source files in your application.
Snowpack includes built-in support to build all TypeScript source files (`.ts` & `.tsx`) in your application.

Snowpack supports live TypeScript type checking right in the Snowpack CLI dev console. Connect the TypeScript compiler (`tsc`) into your workflow using the snippet below.
For automatic TypeScript type checking during development, add the official [@snowpack/plugin-typescript](https://www.npmjs.com/package/@snowpack/plugin-typescript) plugin to your Snowpack config file. This plugin adds automatic `tsc` type checking results right in the Snowpack dev console.

```js
// snowpack.config.json
// Example: Connect TypeScript CLI (tsc) reporting to Snowpack
{
"plugins": [
["@snowpack/plugin-run-script", {"cmd": "tsc --noEmit", "watch": "$1 --watch"}]
]
}
"plugins": ["@snowpack/plugin-typescript"]
```

### Babel
Expand Down
4 changes: 4 additions & 0 deletions docs/docs/10-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ Options:
- When using the Single-Page Application (SPA) pattern, this is the HTML "shell" file that gets served for every (non-resource) user route. Make sure that you configure your production servers to serve this as well.
- **`devOptions.open`** | `string` | Default: `"default"`
- Opens the dev server in a new browser tab. If Chrome is available on macOS, an attempt will be made to reuse an existing browser tab. Any installed browser may also be specified. E.g., "chrome", "firefox", "brave". Set "none" to disable.
- **`devOptions.output`** | `"stream" | "dashboard"` | Default: `"dashboard"`
- Set the output mode of the `dev` console.
- `"dashboard"` delivers an organized layout of console output and the logs of any connected tools. This is recommended for most users and results in the best logging experience.
- `"stream"` is useful when Snowpack is run in parallel with other commands, where clearing the shell would clear important output of other commands running in the same shell.
- **`devOptions.hostname`** | `string` | Default: `localhost`
- The hostname where the browser tab will be open.
- **`devOptions.hmr`** | `boolean` | Default: `true`
Expand Down
3 changes: 2 additions & 1 deletion esinstall/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
},
"scripts": {
"build": "tsc",
"build:watch": "tsc --watch"
"build:watch": "tsc --watch",
"lint": "tsc --noEmit --noUnusedLocals true --noUnusedParameters true"
},
"types": "lib/index.d.ts",
"main": "lib/index.js",
Expand Down
20 changes: 13 additions & 7 deletions esinstall/src/rollup-plugins/rollup-plugin-wrap-install-targets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,20 @@ export function rollupPluginWrapInstallTargets(
* Get the exports that we scanned originally using static analysis. This is meant to run on
* any file (not only CJS) but it will only return an array if CJS exports were found.
*/
function cjsAutoDetectExportsStatic(filename: string): string[] | undefined {
function cjsAutoDetectExportsStatic(filename: string, visited = new Set()): string[] | undefined {
// Prevent infinite loops via circular dependencies.
if (visited.has(filename)) {
return [];
} else {
visited.add(filename);
}
const fileContents = fs.readFileSync(filename, 'utf-8');
try {
const {exports} = parse(fileContents);
// TODO: Also follow & deeply parse dependency "reexports" returned by the lexer.
if (exports.length > 0) {
return exports.filter((imp) => imp !== 'default');
}
const {exports, reexports} = parse(fileContents);
const resolvedReexports = reexports.map((e) =>
cjsAutoDetectExportsStatic(require.resolve(e, {paths: [path.dirname(filename)]}), visited),
);
return Array.from(new Set([...exports, ...resolvedReexports])).filter((imp) => imp !== 'default');
} catch (err) {
// Safe to ignore, this is usually due to the file not being CJS.
logger.debug(`cjsAutoDetectExportsStatic error: ${err.message}`);
Expand Down Expand Up @@ -92,7 +98,7 @@ export function rollupPluginWrapInstallTargets(
const cjsExports = isExplicitAutoDetect
? cjsAutoDetectExportsRuntime(val)
: cjsAutoDetectExportsStatic(val);
if (cjsExports) {
if (cjsExports && cjsExports.length > 0) {
cjsScannedNamedExports.set(normalizedFileLoc, cjsExports);
input[key] = `snowpack-wrap:${val}`;
}
Expand Down
2 changes: 0 additions & 2 deletions esinstall/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
"strict": true,
"sourceMap": true,
"noImplicitAny": false,
"noUnusedLocals": true,
"noUnusedParameters": true,
"skipLibCheck": true
}
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
"bootstrap": "lerna bootstrap",
"build": "lerna run build --scope=esinstall --scope=snowpack",
"build:watch": "lerna run build:watch --parallel --scope=esinstall --scope=snowpack",
"lint": "lerna run lint --parallel --scope=esinstall --scope=snowpack",
"publish": "npm run build && lerna publish --no-private",
"format": "prettier --write '{snowpack,esinstall}/src/**/*.{ts,js}' '{test,plugins}/**/*.{ts,js}' '*.{js,json,md}' '**/*.{json,md}' '.github/**/*.{md,yml}' '!**/{_dist_,build,packages,pkg,TEST_BUILD_OUT,web_modules}/**' !test/create-snowpack-app/test-install",
"test": "jest --test-timeout=30000"
"test": "jest --test-timeout=30000 && yarn run lint"
},
"workspaces": [
"create-snowpack-app/*",
Expand All @@ -30,7 +31,6 @@
"@types/mkdirp": "^1.0.0",
"@types/rimraf": "^3.0.0",
"@types/signal-exit": "^3.0.0",
"@types/tar": "^4.0.3",
"@types/validate-npm-package-name": "^3.0.0",
"@types/ws": "^7.2.4",
"cross-env": "^7.0.2",
Expand Down
48 changes: 48 additions & 0 deletions plugins/plugin-babel/test/plugin-babel.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,54 @@ describe('plugin-babel', () => {
}
`);
});

describe('input option', () => {
test('input option must be an array has at least 1 value', () => {
expect(() =>
plugin(
{
buildOptions: {},
},
{
input: '.js',
},
),
).toThrowErrorMatchingInlineSnapshot(
`"options.input must be an array (e.g. ['.js', '.mjs', '.jsx', '.ts', '.tsx'])"`,
);
expect(() =>
plugin(
{
buildOptions: {},
},
{
input: [],
},
),
).toThrowErrorMatchingInlineSnapshot(`"options.input must specify at least one filetype"`);
});
test('input option will overwrite the default resolve config', () => {
expect(
plugin(
{
buildOptions: {},
},
{
input: ['.js'],
},
).resolve,
).toMatchInlineSnapshot(`
Object {
"input": Array [
".js",
],
"output": Array [
".js",
],
}
`);
});
});
test('has transformOptions', async () => {
const transformOptions = {
ast: true,
Expand Down
7 changes: 0 additions & 7 deletions plugins/plugin-run-script/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,13 @@ function runScriptPlugin(_, {cmd, watch, output}) {
}
if (stdOutput.includes('\u001bc') || stdOutput.includes('\x1Bc')) {
log('WORKER_RESET', {});
log('WORKER_UPDATE', {state: ['RUNNING', 'yellow']});
stdOutput = stdOutput.replace(/\x1Bc/, '').replace(/\u001bc/, '');
}
if (cmdProgram === 'tsc') {
if (/Watching for file changes./gm.test(stdOutput)) {
log('WORKER_UPDATE', {state: ['RUNNING', 'yellow']});
}
const errorMatch = stdOutput.match(/Found (\d+) error/);
if (errorMatch) {
if (errorMatch[1] === '0') {
log('WORKER_UPDATE', {state: ['OK', 'green']});
stdOutput = stdOutput.trim();
} else {
log('WORKER_UPDATE', {state: ['ERROR', 'red']});
}
}
}
Expand Down
Loading

0 comments on commit 12f303d

Please sign in to comment.