-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14069 from NervJS/feat/build-clean
feat(mp\h5): 支持 output.clean 选项
- Loading branch information
Showing
81 changed files
with
349 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/babel-plugin-transform-react-jsx-to-rn-stylesheet/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "babel-preset-taro", | ||
"version": "3.6.9-alpha.5", | ||
"version": "3.6.9-alpha.7", | ||
"description": "Taro babel preset", | ||
"author": "yuche <[email protected]>", | ||
"homepage": "https://github.com/nervjs/taro/tree/master/packages/babel-preset-taro#readme", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@tarojs/create-app", | ||
"version": "3.6.9-alpha.5", | ||
"version": "3.6.9-alpha.7", | ||
"description": "create taro app with one command", | ||
"author": "VincentW <[email protected]>", | ||
"homepage": "https://github.com/nervjs/taro/tree/master/packages/create-app#readme", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@tarojs/shared", | ||
"version": "3.6.9-alpha.5", | ||
"version": "3.6.9-alpha.7", | ||
"description": "Taro utils internal use.", | ||
"author": "yuche <[email protected]>", | ||
"homepage": "https://github.com/nervjs/taro/tree/master/packages/shared#readme", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@tarojs/api", | ||
"version": "3.6.9-alpha.5", | ||
"version": "3.6.9-alpha.7", | ||
"description": "Taro common API", | ||
"author": "yuche <[email protected]>", | ||
"homepage": "https://github.com/nervjs/taro/tree/master/packages/api#readme", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import { emptyDirectory } from '@tarojs/helper' | ||
import * as path from 'path' | ||
|
||
import { run } from './utils' | ||
|
||
const runBuild = run('build', [ | ||
'commands/build', | ||
require.resolve('@tarojs/plugin-platform-weapp'), | ||
require.resolve('@tarojs/plugin-platform-h5') | ||
]) | ||
|
||
jest.mock('@tarojs/helper', () => { | ||
const helper = jest.requireActual('@tarojs/helper') | ||
const fs = helper.fs | ||
return { | ||
__esModule: true, | ||
...helper, | ||
emptyDirectory: jest.fn(), | ||
fs: { | ||
...fs | ||
}, | ||
} | ||
}) | ||
|
||
const APP_PATH = path.join(__dirname, 'fixtures/default') | ||
const OUTPUT_PATH = path.join(__dirname, 'fixtures/default/dist') | ||
|
||
describe('构建配置测试', () => { | ||
const emptyDirectoryMocked = emptyDirectory as jest.Mock<any> | ||
|
||
beforeEach(() => { | ||
emptyDirectoryMocked.mockReset() | ||
process.argv = [] | ||
}) | ||
|
||
afterEach(() => { | ||
process.argv = [] | ||
emptyDirectoryMocked.mockReset() | ||
}) | ||
|
||
describe('小程序', () => { | ||
it(`项目 output.clean = clean: { keep: ['project.config.json'] } ==> 清空dist文件夹但保留指定文件`, async () => { | ||
const exitSpy = jest.spyOn(process, 'exit') as jest.SpyInstance<void, any> | ||
const logSpy = jest.spyOn(console, 'log') | ||
const errorSpy = jest.spyOn(console, 'error') | ||
logSpy.mockImplementation(() => {}) | ||
errorSpy.mockImplementation(() => {}) | ||
exitSpy.mockImplementation(() => { | ||
throw new Error() | ||
}) | ||
|
||
try { | ||
await runBuild(APP_PATH, { | ||
options: { | ||
type: 'weapp', | ||
platform: 'weapp' | ||
} | ||
}) | ||
} catch (error) { | ||
// no handler | ||
} | ||
expect(emptyDirectoryMocked).toBeCalledWith(OUTPUT_PATH, { excludes: ['project.config.json'] }) | ||
|
||
exitSpy.mockRestore() | ||
logSpy.mockRestore() | ||
errorSpy.mockRestore() | ||
}) | ||
}) | ||
|
||
describe('h5', () => { | ||
it('output.clean = false ==> 保留dist文件夹', async () => { | ||
const exitSpy = jest.spyOn(process, 'exit') as jest.SpyInstance<void, any> | ||
const logSpy = jest.spyOn(console, 'log') | ||
const errorSpy = jest.spyOn(console, 'error') | ||
logSpy.mockImplementation(() => {}) | ||
errorSpy.mockImplementation(() => {}) | ||
exitSpy.mockImplementation(() => { | ||
throw new Error() | ||
}) | ||
|
||
try { | ||
await runBuild(APP_PATH, { | ||
options: { | ||
type: 'h5', | ||
platform: 'h5' | ||
} | ||
}) | ||
} catch (error) { | ||
// no handler | ||
} | ||
expect(emptyDirectoryMocked).toBeCalledTimes(0) | ||
|
||
exitSpy.mockRestore() | ||
logSpy.mockRestore() | ||
errorSpy.mockRestore() | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import { Kernel } from '@tarojs/service' | ||
import * as path from 'path' | ||
|
||
import CLI from '../cli' | ||
import { dotenvParse } from '../util/index' | ||
|
||
jest.mock('@tarojs/service') | ||
const MockedKernel = Kernel as unknown as jest.Mock<Kernel> | ||
const APP_PATH = path.join(__dirname, 'fixtures/default') | ||
|
||
function setProcessArgv (cmd: string) { | ||
// @ts-ignore | ||
process.argv = [null, ...cmd.split(' ')] | ||
} | ||
|
||
describe('inspect', () => { | ||
let cli: CLI | ||
|
||
beforeAll(() => { | ||
cli = new CLI(APP_PATH) | ||
}) | ||
|
||
beforeEach(() => { | ||
MockedKernel.mockClear() | ||
process.argv = [] | ||
delete process.env.NODE_ENV | ||
delete process.env.TARO_ENV | ||
delete process.env.TARO_APP_TEST | ||
delete process.env.TARO_APP_ID | ||
delete process.env.JD_APP_TEST | ||
delete process.env.TARO_APP_DEFAULT | ||
delete process.env.TARO_APP_FOO | ||
}) | ||
|
||
afterEach(() => { | ||
MockedKernel.mockClear() | ||
process.argv = [] | ||
delete process.env.NODE_ENV | ||
delete process.env.TARO_ENV | ||
delete process.env.TARO_APP_TEST | ||
delete process.env.TARO_APP_ID | ||
delete process.env.JD_APP_TEST | ||
delete process.env.TARO_APP_DEFAULT | ||
delete process.env.TARO_APP_FOO | ||
}) | ||
|
||
describe('cli mode env', () => { | ||
|
||
it('dotenvParse .env .env.dev should success', async () => { | ||
expect(process.env.TARO_test).toBeUndefined() | ||
dotenvParse(path.resolve(__dirname, 'env'), 'TARO_', 'dev') | ||
expect(process.env.TARO_test).toBe('123') | ||
expect(process.env._TARO_test).toBeUndefined() | ||
}) | ||
|
||
it('--watch true => 默认加载 .env.development', async () => { | ||
setProcessArgv('taro build --watch --type weapp') | ||
await cli.run() | ||
expect(process.env.TARO_APP_TEST).toEqual('env-development') | ||
expect(process.env.TARO_APP_DEFAULT).toEqual('default') | ||
}) | ||
|
||
it('--watch false => 默认加载 .env.production', async () => { | ||
setProcessArgv('taro build --type weapp') | ||
await cli.run() | ||
expect(process.env.TARO_APP_TEST).toEqual('env-production') | ||
expect(process.env.TARO_APP_DEFAULT).toEqual('default') | ||
}) | ||
|
||
it('指定加载 .env.pre', async () => { | ||
setProcessArgv('taro build --type weapp --mode pre') | ||
await cli.run() | ||
expect(process.env.TARO_APP_TEST).toEqual('env-pre') | ||
expect(process.env.TARO_APP_DEFAULT).toEqual('default') | ||
}) | ||
|
||
it('env.local 比 .env 优先级更高', async () => { | ||
setProcessArgv('taro build --type weapp --mode find404') | ||
await cli.run() | ||
expect(process.env.TARO_APP_TEST).toEqual('env-local') | ||
expect(process.env.TARO_APP_DEFAULT).toEqual('default') | ||
}) | ||
|
||
it('env.uat.local 比 .env.uat 优先级更高', async () => { | ||
setProcessArgv('taro build --type weapp --mode uat') | ||
await cli.run() | ||
expect(process.env.TARO_APP_TEST).toEqual('env-uat-local') | ||
expect(process.env.TARO_APP_DEFAULT).toEqual('default') | ||
}) | ||
|
||
it('自定义前缀: JD_APP_', async () => { | ||
setProcessArgv('taro build --type weapp --mode uat --env-prefix JD_APP_') | ||
await cli.run() | ||
expect(process.env.JD_APP_TEST).toEqual('env-uat') | ||
expect(process.env.TARO_APP_TEST).toEqual(undefined) | ||
expect(process.env.TARO_APP_ID).toEqual('特殊变量appid') | ||
}) | ||
|
||
it('环境变量可以相互引用', async () => { | ||
setProcessArgv('taro build --type weapp --mode pre') | ||
await cli.run() | ||
expect(process.env.TARO_APP_FOO).toEqual('env-pre-foo') | ||
}) | ||
}) | ||
}) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
TARO_APP_TEST=env | ||
|
||
TARO_APP_DEFAULT=default |
1 change: 1 addition & 0 deletions
1
packages/taro-cli/src/__tests__/fixtures/default/.env.development
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
TARO_APP_TEST=env-development |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
TARO_APP_TEST=env-local |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
TARO_APP_TEST=env-pre | ||
|
||
TARO_APP_FOO=${TARO_APP_TEST}-foo |
1 change: 1 addition & 0 deletions
1
packages/taro-cli/src/__tests__/fixtures/default/.env.production
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
TARO_APP_TEST=env-production |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
TARO_APP_TEST=env-uat | ||
|
||
JD_APP_TEST=env-uat | ||
|
||
TARO_APP_ID=特殊变量appid |
1 change: 1 addition & 0 deletions
1
packages/taro-cli/src/__tests__/fixtures/default/.env.uat.local
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
TARO_APP_TEST=env-uat-local |
Oops, something went wrong.