@adobe/aio-lib-web 7.1.1 → 7.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/dependabot-coverage-upload.yml +33 -0
- package/.github/workflows/pr-review.yml +62 -0
- package/e2e/e2e.js +12 -4
- package/package.json +3 -3
- package/src/build-web.js +11 -1
- package/src/bundle.js +28 -6
- package/src/constants.js +19 -0
- package/test/src/build-web.test.js +40 -1
- package/test/src/bundle.test.js +52 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
name: Dependabot Coverage Upload
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
issue_comment:
|
|
5
|
+
types: [created]
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
check:
|
|
9
|
+
if: github.event.issue.pull_request != null && github.event.comment.body == '/upload-coverage'
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
outputs:
|
|
12
|
+
allowed: ${{ steps.gate.outputs.allowed }}
|
|
13
|
+
steps:
|
|
14
|
+
- name: Gate check
|
|
15
|
+
id: gate
|
|
16
|
+
run: |
|
|
17
|
+
set -euo pipefail
|
|
18
|
+
PERM=$(gh api "repos/$GITHUB_REPOSITORY/collaborators/$COMMENT_USER_LOGIN/permission" --jq '.permission' 2>/dev/null || echo "none")
|
|
19
|
+
if [ "$PERM" = "admin" ] || [ "$PERM" = "maintain" ]; then
|
|
20
|
+
echo "allowed=true" >> $GITHUB_OUTPUT
|
|
21
|
+
else
|
|
22
|
+
echo "allowed=false" >> $GITHUB_OUTPUT
|
|
23
|
+
fi
|
|
24
|
+
env:
|
|
25
|
+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
26
|
+
COMMENT_USER_LOGIN: ${{ github.event.comment.user.login }}
|
|
27
|
+
|
|
28
|
+
upload:
|
|
29
|
+
needs: check
|
|
30
|
+
if: needs.check.outputs.allowed == 'true'
|
|
31
|
+
uses: adobe/aio-reusable-workflows/.github/workflows/dependabot-coverage-upload.yml@main
|
|
32
|
+
secrets:
|
|
33
|
+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
name: PR Review
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
types: [opened, reopened, synchronize]
|
|
6
|
+
issue_comment:
|
|
7
|
+
types: [created]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
check:
|
|
11
|
+
# NOTE: comment body matching is exact — /review or /pr-reviewer with no trailing spaces, newlines, or mixed case
|
|
12
|
+
# This does not fail the workflow; non-matching comments simply do not trigger the job
|
|
13
|
+
if: |
|
|
14
|
+
(github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == false) ||
|
|
15
|
+
(github.event_name == 'issue_comment' && github.event.issue.pull_request != null &&
|
|
16
|
+
(github.event.comment.body == '/review' || github.event.comment.body == '/pr-reviewer'))
|
|
17
|
+
runs-on: ubuntu-latest
|
|
18
|
+
outputs:
|
|
19
|
+
allowed: ${{ steps.gate.outputs.allowed }}
|
|
20
|
+
pr_number: ${{ steps.gate.outputs.pr_number }}
|
|
21
|
+
head_sha: ${{ steps.gate.outputs.head_sha }}
|
|
22
|
+
steps:
|
|
23
|
+
- name: Gate check
|
|
24
|
+
id: gate
|
|
25
|
+
run: |
|
|
26
|
+
set -euo pipefail
|
|
27
|
+
if [ "$EVENT_NAME" = "pull_request" ]; then
|
|
28
|
+
echo "allowed=true" >> $GITHUB_OUTPUT
|
|
29
|
+
echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT
|
|
30
|
+
echo "head_sha=$HEAD_SHA" >> $GITHUB_OUTPUT
|
|
31
|
+
else
|
|
32
|
+
# Fall back to "none" if user is not a collaborator (gh api returns 404) so allowed=false is output cleanly
|
|
33
|
+
PERM=$(gh api repos/$GITHUB_REPOSITORY/collaborators/$COMMENT_USER_LOGIN/permission --jq '.permission' 2>/dev/null || echo "none")
|
|
34
|
+
# Intentionally require admin or maintain; write collaborators are excluded to
|
|
35
|
+
# limit who can trigger potentially expensive/sensitive review automation.
|
|
36
|
+
if [ "$PERM" = "admin" ] || [ "$PERM" = "maintain" ]; then
|
|
37
|
+
DATA=$(gh api repos/$GITHUB_REPOSITORY/pulls/$ISSUE_NUMBER)
|
|
38
|
+
echo "allowed=true" >> $GITHUB_OUTPUT
|
|
39
|
+
echo "pr_number=$ISSUE_NUMBER" >> $GITHUB_OUTPUT
|
|
40
|
+
echo "head_sha=$(echo "$DATA" | jq -r '.head.sha')" >> $GITHUB_OUTPUT
|
|
41
|
+
else
|
|
42
|
+
echo "allowed=false" >> $GITHUB_OUTPUT
|
|
43
|
+
fi
|
|
44
|
+
fi
|
|
45
|
+
env:
|
|
46
|
+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
47
|
+
EVENT_NAME: ${{ github.event_name }}
|
|
48
|
+
PR_NUMBER: ${{ github.event.pull_request.number }}
|
|
49
|
+
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
|
|
50
|
+
COMMENT_USER_LOGIN: ${{ github.event.comment.user.login }}
|
|
51
|
+
ISSUE_NUMBER: ${{ github.event.issue.number }}
|
|
52
|
+
# GITHUB_REPOSITORY is set automatically by GitHub Actions (owner/repo)
|
|
53
|
+
|
|
54
|
+
review:
|
|
55
|
+
needs: check
|
|
56
|
+
if: needs.check.outputs.allowed == 'true'
|
|
57
|
+
uses: adobe/aio-reusable-workflows/.github/workflows/pr-review.yml@main
|
|
58
|
+
with:
|
|
59
|
+
pr_number: ${{ needs.check.outputs.pr_number }}
|
|
60
|
+
head_sha: ${{ needs.check.outputs.head_sha }}
|
|
61
|
+
secrets:
|
|
62
|
+
AWS_BEARER_TOKEN_BEDROCK: ${{ secrets.APP_BUILDER_AWS_BEARER_TOKEN_BEDROCK }}
|
package/e2e/e2e.js
CHANGED
|
@@ -25,7 +25,9 @@ const undeployWeb = require('../src/undeploy-web')
|
|
|
25
25
|
const ENTRY_FILE = path.join(__dirname, 'sample-app/index.html')
|
|
26
26
|
const DEST_FOLDER = path.join(__dirname, 'dist/')
|
|
27
27
|
const CACHE_FILE = path.join(__dirname, '.cache')
|
|
28
|
-
|
|
28
|
+
|
|
29
|
+
// Regex to capture the `src` attribute of a `<script>` tag.
|
|
30
|
+
const SRC_REGEX = /<script.*src=["']?(?<src>[^"'\s>]+)["']?/
|
|
29
31
|
|
|
30
32
|
const config = {
|
|
31
33
|
app: {
|
|
@@ -97,15 +99,21 @@ describe('e2e', () => {
|
|
|
97
99
|
})
|
|
98
100
|
|
|
99
101
|
test('undeploy', async () => {
|
|
100
|
-
let error, response
|
|
102
|
+
let error, response, contents
|
|
101
103
|
try {
|
|
102
104
|
await undeployWeb(config)
|
|
103
|
-
|
|
105
|
+
// undeployWeb empties the S3 origin, but CloudFront may still serve the previously cached page on the canonical URL for its default TTL
|
|
106
|
+
// Adding a unique query string bypasses the edge cache so we read the current origin state.
|
|
107
|
+
response = await fetch(`${url}?nocache=${Date.now()}`)
|
|
108
|
+
contents = await response.text()
|
|
104
109
|
} catch (e) {
|
|
105
110
|
error = e
|
|
106
111
|
console.error(e)
|
|
107
112
|
}
|
|
108
113
|
expect(error).toBeUndefined()
|
|
109
|
-
|
|
114
|
+
// assert that CDN serves its not-found page.
|
|
115
|
+
expect(response.status).toEqual(200)
|
|
116
|
+
expect(contents).toContain('404 Not Found')
|
|
117
|
+
expect(contents).toContain('The page you requested cannot be found.')
|
|
110
118
|
})
|
|
111
119
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adobe/aio-lib-web",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.3.0",
|
|
4
4
|
"description": "Utility tooling library to build and deploy Adobe I/O Project Firefly app static sites to CDN",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"directories": {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"author": "Adobe Inc.",
|
|
11
11
|
"license": "Apache-2.0",
|
|
12
12
|
"engines": {
|
|
13
|
-
"node": ">=
|
|
13
|
+
"node": ">=20"
|
|
14
14
|
},
|
|
15
15
|
"repository": "adobe/aio-lib-web",
|
|
16
16
|
"homepage": "https://github.com/adobe/aio-lib-web",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"@adobe/aio-lib-core-config": "^5",
|
|
33
33
|
"@adobe/aio-lib-core-logging": "^3",
|
|
34
34
|
"@adobe/aio-lib-core-tvm": "^4",
|
|
35
|
-
"@aws-sdk/client-s3": "^3.
|
|
35
|
+
"@aws-sdk/client-s3": "^3.1045.0",
|
|
36
36
|
"@smithy/node-http-handler": "^4.0.2",
|
|
37
37
|
"core-js": "^3.25.1",
|
|
38
38
|
"fs-extra": "^11",
|
package/src/build-web.js
CHANGED
|
@@ -14,6 +14,8 @@ const fs = require('fs-extra')
|
|
|
14
14
|
const path = require('path')
|
|
15
15
|
const Bundler = require('@parcel/core').default
|
|
16
16
|
|
|
17
|
+
const { DEVELOPMENT_ENV, PRODUCTION_ENV } = require('./constants')
|
|
18
|
+
|
|
17
19
|
/**
|
|
18
20
|
* @deprecated since 4.1.0 ( January, 2021 ), use `bundle` instead
|
|
19
21
|
*/
|
|
@@ -25,6 +27,9 @@ const buildWeb = async (config, log) => {
|
|
|
25
27
|
const dist = config.web.distProd
|
|
26
28
|
const src = config.web.src
|
|
27
29
|
|
|
30
|
+
const nodeEnv = process.env.NODE_ENV || DEVELOPMENT_ENV
|
|
31
|
+
const mode = nodeEnv === PRODUCTION_ENV ? PRODUCTION_ENV : DEVELOPMENT_ENV
|
|
32
|
+
|
|
28
33
|
// clean/create needed dirs
|
|
29
34
|
await fs.emptyDir(dist)
|
|
30
35
|
|
|
@@ -32,10 +37,15 @@ const buildWeb = async (config, log) => {
|
|
|
32
37
|
const bundler = new Bundler({
|
|
33
38
|
entries: path.join(src, 'index.html'),
|
|
34
39
|
defaultConfig: require.resolve('@parcel/config-default'),
|
|
40
|
+
mode,
|
|
41
|
+
env: {
|
|
42
|
+
NODE_ENV: nodeEnv
|
|
43
|
+
},
|
|
35
44
|
shouldDisableCache: true,
|
|
36
45
|
defaultTargetOptions: {
|
|
37
46
|
distDir: dist,
|
|
38
|
-
publicUrl: './'
|
|
47
|
+
publicUrl: './',
|
|
48
|
+
shouldOptimize: mode === 'production'
|
|
39
49
|
},
|
|
40
50
|
logLevel: 'none',
|
|
41
51
|
shouldContentHash: true
|
package/src/bundle.js
CHANGED
|
@@ -13,6 +13,8 @@ governing permissions and limitations under the License.
|
|
|
13
13
|
const Bundler = require('@parcel/core').default
|
|
14
14
|
const aioLogger = require('@adobe/aio-lib-core-logging')('@adobe/aio-lib-web:bundle', { provider: 'debug' })
|
|
15
15
|
|
|
16
|
+
const { DEVELOPMENT_ENV, PRODUCTION_ENV } = require('./constants')
|
|
17
|
+
|
|
16
18
|
/**
|
|
17
19
|
* @typedef {object} BundleWebObject
|
|
18
20
|
* @property {object} the Parcel bundler object
|
|
@@ -26,6 +28,10 @@ const aioLogger = require('@adobe/aio-lib-core-logging')('@adobe/aio-lib-web:bun
|
|
|
26
28
|
* @property {boolean} watch
|
|
27
29
|
* @property {boolean} minify
|
|
28
30
|
* @property {number} logLevel
|
|
31
|
+
* @property {'development'|'production'} mode
|
|
32
|
+
* @property {object} env
|
|
33
|
+
* @property {object} defaultTargetOptions
|
|
34
|
+
* @property {boolean} shouldOptimize
|
|
29
35
|
*/
|
|
30
36
|
|
|
31
37
|
/**
|
|
@@ -37,7 +43,7 @@ const aioLogger = require('@adobe/aio-lib-core-logging')('@adobe/aio-lib-web:bun
|
|
|
37
43
|
* @param {Function} [log] the app logger
|
|
38
44
|
* @returns {BundleWebObject} the BundleWebObject
|
|
39
45
|
*/
|
|
40
|
-
module.exports = async (entries, dest, options = {
|
|
46
|
+
module.exports = async (entries, dest, options = {}, log = () => {}) => {
|
|
41
47
|
aioLogger.debug(`bundle options: ${JSON.stringify(options, null, 2)}`)
|
|
42
48
|
|
|
43
49
|
if (!entries) {
|
|
@@ -47,6 +53,16 @@ module.exports = async (entries, dest, options = { shouldOptimize: false }, log
|
|
|
47
53
|
throw new Error('cannot build web, missing destination')
|
|
48
54
|
}
|
|
49
55
|
|
|
56
|
+
const {
|
|
57
|
+
defaultTargetOptions = {},
|
|
58
|
+
env = {},
|
|
59
|
+
shouldOptimize,
|
|
60
|
+
...parcelOptions
|
|
61
|
+
} = options
|
|
62
|
+
|
|
63
|
+
const nodeEnv = env.NODE_ENV || process.env.NODE_ENV || DEVELOPMENT_ENV
|
|
64
|
+
const mode = parcelOptions.mode || (nodeEnv === PRODUCTION_ENV ? PRODUCTION_ENV : DEVELOPMENT_ENV)
|
|
65
|
+
|
|
50
66
|
// set defaults, but allow override by passed in values
|
|
51
67
|
const parcelBundleOptions = {
|
|
52
68
|
entries,
|
|
@@ -58,14 +74,20 @@ module.exports = async (entries, dest, options = { shouldOptimize: false }, log
|
|
|
58
74
|
distDir: dest
|
|
59
75
|
}
|
|
60
76
|
},
|
|
61
|
-
defaultTargetOptions: {
|
|
62
|
-
distDir: dest,
|
|
63
|
-
shouldOptimize: options.shouldOptimize
|
|
64
|
-
},
|
|
65
77
|
shouldPatchConsole: false,
|
|
66
78
|
shouldContentHash: true,
|
|
67
79
|
logLevel: 'error',
|
|
68
|
-
...
|
|
80
|
+
...parcelOptions,
|
|
81
|
+
mode,
|
|
82
|
+
env: {
|
|
83
|
+
...env,
|
|
84
|
+
NODE_ENV: nodeEnv
|
|
85
|
+
},
|
|
86
|
+
defaultTargetOptions: {
|
|
87
|
+
distDir: dest,
|
|
88
|
+
...defaultTargetOptions,
|
|
89
|
+
shouldOptimize: defaultTargetOptions.shouldOptimize ?? shouldOptimize ?? mode === 'production'
|
|
90
|
+
}
|
|
69
91
|
}
|
|
70
92
|
|
|
71
93
|
aioLogger.debug(`bundle bundleOptions: ${JSON.stringify(parcelBundleOptions, null, 2)}`)
|
package/src/constants.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const DEVELOPMENT_ENV = 'development'
|
|
14
|
+
const PRODUCTION_ENV = 'production'
|
|
15
|
+
|
|
16
|
+
module.exports = {
|
|
17
|
+
DEVELOPMENT_ENV,
|
|
18
|
+
PRODUCTION_ENV
|
|
19
|
+
}
|
|
@@ -15,6 +15,7 @@ const { vol } = global.mockFs()
|
|
|
15
15
|
const buildWeb = require('../../src/build-web')
|
|
16
16
|
const fs = require('fs-extra')
|
|
17
17
|
jest.mock('fs-extra')
|
|
18
|
+
const originalNodeEnv = process.env.NODE_ENV
|
|
18
19
|
|
|
19
20
|
describe('build-web', () => {
|
|
20
21
|
beforeEach(() => {
|
|
@@ -24,6 +25,14 @@ describe('build-web', () => {
|
|
|
24
25
|
global.cleanFs(vol)
|
|
25
26
|
})
|
|
26
27
|
|
|
28
|
+
afterEach(() => {
|
|
29
|
+
if (originalNodeEnv === undefined) {
|
|
30
|
+
delete process.env.NODE_ENV
|
|
31
|
+
} else {
|
|
32
|
+
process.env.NODE_ENV = originalNodeEnv
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
|
|
27
36
|
test('throws if config does not have an app, or frontEnd', async () => {
|
|
28
37
|
await expect(buildWeb()).rejects.toThrow('cannot build web')
|
|
29
38
|
await expect(buildWeb({ app: 'nothing-here' })).rejects.toThrow('cannot build web')
|
|
@@ -51,6 +60,7 @@ describe('build-web', () => {
|
|
|
51
60
|
})
|
|
52
61
|
|
|
53
62
|
test('check build options', async () => {
|
|
63
|
+
delete process.env.NODE_ENV
|
|
54
64
|
const config = {
|
|
55
65
|
app: {
|
|
56
66
|
hasFrontend: true
|
|
@@ -68,13 +78,42 @@ describe('build-web', () => {
|
|
|
68
78
|
defaultConfig: expect.stringContaining(path.join('parcel', 'config-default', 'index.json')),
|
|
69
79
|
defaultTargetOptions: expect.objectContaining({
|
|
70
80
|
distDir: 'dist',
|
|
71
|
-
publicUrl: './'
|
|
81
|
+
publicUrl: './',
|
|
82
|
+
shouldOptimize: false
|
|
72
83
|
}),
|
|
84
|
+
env: expect.objectContaining({ NODE_ENV: 'development' }),
|
|
73
85
|
entries: path.join('fakeDir', 'index.html'),
|
|
74
86
|
logLevel: 'none',
|
|
87
|
+
mode: 'development',
|
|
75
88
|
shouldContentHash: true,
|
|
76
89
|
shouldDisableCache: true
|
|
77
90
|
})
|
|
78
91
|
])
|
|
79
92
|
})
|
|
93
|
+
|
|
94
|
+
test('uses production build options from NODE_ENV', async () => {
|
|
95
|
+
process.env.NODE_ENV = 'production'
|
|
96
|
+
const config = {
|
|
97
|
+
app: {
|
|
98
|
+
hasFrontend: true
|
|
99
|
+
},
|
|
100
|
+
web: {
|
|
101
|
+
distProd: 'dist',
|
|
102
|
+
src: 'fakeDir'
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
global.addFakeFiles(vol, 'fakeDir', { 'index.html': '' })
|
|
106
|
+
fs.readdir.mockReturnValue(['output.html'])
|
|
107
|
+
|
|
108
|
+
await expect(buildWeb(config)).resolves.toEqual(['output.html'])
|
|
109
|
+
expect(global._bundler__arguments).toEqual([
|
|
110
|
+
expect.objectContaining({
|
|
111
|
+
defaultTargetOptions: expect.objectContaining({
|
|
112
|
+
shouldOptimize: true
|
|
113
|
+
}),
|
|
114
|
+
env: expect.objectContaining({ NODE_ENV: 'production' }),
|
|
115
|
+
mode: 'production'
|
|
116
|
+
})
|
|
117
|
+
])
|
|
118
|
+
})
|
|
80
119
|
})
|
package/test/src/bundle.test.js
CHANGED
|
@@ -15,6 +15,7 @@ const bundle = require('../../src/bundle')
|
|
|
15
15
|
const fs = require('fs-extra')
|
|
16
16
|
jest.mock('fs-extra')
|
|
17
17
|
const path = require('path')
|
|
18
|
+
const originalNodeEnv = process.env.NODE_ENV
|
|
18
19
|
|
|
19
20
|
describe('bundle', () => {
|
|
20
21
|
beforeEach(() => {
|
|
@@ -24,6 +25,14 @@ describe('bundle', () => {
|
|
|
24
25
|
global.cleanFs(vol)
|
|
25
26
|
})
|
|
26
27
|
|
|
28
|
+
afterEach(() => {
|
|
29
|
+
if (originalNodeEnv === undefined) {
|
|
30
|
+
delete process.env.NODE_ENV
|
|
31
|
+
} else {
|
|
32
|
+
process.env.NODE_ENV = originalNodeEnv
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
|
|
27
36
|
test('throws if config does not have an app, or frontEnd', async () => {
|
|
28
37
|
// much of this is actually now the callers responsibility
|
|
29
38
|
await expect(bundle()).rejects.toThrow('cannot build web')
|
|
@@ -49,6 +58,7 @@ describe('bundle', () => {
|
|
|
49
58
|
})
|
|
50
59
|
|
|
51
60
|
test('check build options', async () => {
|
|
61
|
+
delete process.env.NODE_ENV
|
|
52
62
|
global.addFakeFiles(vol, 'fakeDir', { 'index.html': '' })
|
|
53
63
|
await expect(bundle('fakeDir/index.html', 'distProd')).resolves.toEqual(expect.any(Object))
|
|
54
64
|
expect(global._bundler__arguments).toEqual([
|
|
@@ -58,8 +68,10 @@ describe('bundle', () => {
|
|
|
58
68
|
distDir: 'distProd',
|
|
59
69
|
shouldOptimize: false
|
|
60
70
|
}),
|
|
71
|
+
env: expect.objectContaining({ NODE_ENV: 'development' }),
|
|
61
72
|
entries: 'fakeDir/index.html',
|
|
62
73
|
logLevel: 'error',
|
|
74
|
+
mode: 'development',
|
|
63
75
|
shouldContentHash: true,
|
|
64
76
|
shouldDisableCache: false
|
|
65
77
|
})])
|
|
@@ -99,6 +111,46 @@ describe('bundle', () => {
|
|
|
99
111
|
})])
|
|
100
112
|
})
|
|
101
113
|
|
|
114
|
+
test('uses production build options from NODE_ENV', async () => {
|
|
115
|
+
process.env.NODE_ENV = 'production'
|
|
116
|
+
global.addFakeFiles(vol, 'fakeDir', { 'index.html': '' })
|
|
117
|
+
|
|
118
|
+
await expect(bundle('fakeDir/index.html', 'distProd')).resolves.toEqual(expect.any(Object))
|
|
119
|
+
expect(global._bundler__arguments).toEqual([
|
|
120
|
+
expect.objectContaining({
|
|
121
|
+
defaultTargetOptions: expect.objectContaining({
|
|
122
|
+
distDir: 'distProd',
|
|
123
|
+
shouldOptimize: true
|
|
124
|
+
}),
|
|
125
|
+
env: expect.objectContaining({ NODE_ENV: 'production' }),
|
|
126
|
+
mode: 'production'
|
|
127
|
+
})])
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
test('allows explicit Parcel mode, environment and target option overrides', async () => {
|
|
131
|
+
process.env.NODE_ENV = 'development'
|
|
132
|
+
global.addFakeFiles(vol, 'fakeDir', { 'index.html': '' })
|
|
133
|
+
|
|
134
|
+
await expect(bundle('fakeDir/index.html', 'distProd', {
|
|
135
|
+
mode: 'production',
|
|
136
|
+
env: { NODE_ENV: 'production', CUSTOM_ENV: 'custom' },
|
|
137
|
+
defaultTargetOptions: { publicUrl: './', shouldOptimize: false }
|
|
138
|
+
})).resolves.toEqual(expect.any(Object))
|
|
139
|
+
expect(global._bundler__arguments).toEqual([
|
|
140
|
+
expect.objectContaining({
|
|
141
|
+
defaultTargetOptions: expect.objectContaining({
|
|
142
|
+
distDir: 'distProd',
|
|
143
|
+
publicUrl: './',
|
|
144
|
+
shouldOptimize: false
|
|
145
|
+
}),
|
|
146
|
+
env: {
|
|
147
|
+
NODE_ENV: 'production',
|
|
148
|
+
CUSTOM_ENV: 'custom'
|
|
149
|
+
},
|
|
150
|
+
mode: 'production'
|
|
151
|
+
})])
|
|
152
|
+
})
|
|
153
|
+
|
|
102
154
|
test('returns {bundle, cleanup}', async () => {
|
|
103
155
|
global.addFakeFiles(vol, 'fakeDir', { 'index.html': '' })
|
|
104
156
|
|