Skip to content

Commit

Permalink
release 2.3.1 (#284)
Browse files Browse the repository at this point in the history
* chore: 🤖 pkg version

* fix: 🐛 falsy values will trapped by proxy window (#283)

* fix: 🐛 falsy values will trapped by proxy window

* feat: 🎸 parse library the right way if library is an array (#288)

✅ Closes: #287
  • Loading branch information
maoxiaoke authored Apr 14, 2021
1 parent 3f4ec98 commit cdb9d6c
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

See [https://github.com/ice-lab/icestark/releases](https://github.com/ice-lab/icestark/releases) for what has changed in each version of icestark.

## 2.3.1

- [fix] parse `library` the right way if `library` is an array. ([#287](https://github.com/ice-lab/icestark/issues/287))

## 2.3.0

- [feat] support `prefetch` sub-application, which let your micro application fly. ([#188](https://github.com/ice-lab/icestark/issues/188))
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ice/stark",
"version": "2.3.0",
"version": "2.3.1",
"description": "Icestark is a JavaScript library for multiple projects, Ice workbench solution.",
"scripts": {
"install:deps": "rm -rf node_modules && rm -rf ./packages/*/node_modules && yarn install && lerna exec -- npm install",
Expand Down
4 changes: 4 additions & 0 deletions packages/icestark-app/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.4.1

- [feat] correct types of `setLibraryName`. ([#287](https://github.com/ice-lab/icestark/issues/287))

## 1.4.0

- [feat] add function `setBasename`.
Expand Down
2 changes: 1 addition & 1 deletion packages/icestark-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ice/stark-app",
"version": "1.4.0",
"version": "1.4.1",
"description": "icestark-app is a JavaScript library for icestark, used by sub-application.",
"scripts": {
"build": "rm -rf lib && tsc",
Expand Down
2 changes: 1 addition & 1 deletion packages/icestark-app/src/setLibraryName.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { setCache } from './cache';

const setLibraryName = (library: string): void => {
const setLibraryName = (library: string | string[]): void => {
if (!library) {
console.error('[@ice/stark-app] setLibraryName: params can not be empty!');
return;
Expand Down
3 changes: 3 additions & 0 deletions packages/icestark-sandbox/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 1.1.1

- [fix] falsy values except `undefined` would be trapped by proxy window. ([#156](https://github.com/ice-lab/icestark/issues/156))
## 1.1.0

- [feat] mark access to all properties added to local window by using method `getAddedProperties`.
Expand Down
2 changes: 1 addition & 1 deletion packages/icestark-sandbox/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ice/sandbox",
"version": "1.1.0",
"version": "1.1.1",
"description": "sandbox for execute scripts",
"main": "lib/index.js",
"scripts": {
Expand Down
5 changes: 4 additions & 1 deletion packages/icestark-sandbox/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,10 @@ export default class Sandbox {
}

const targetValue = target[p];
if (targetValue) {
/**
* Falsy value like 0/ ''/ false should be trapped by proxy window.
*/
if (targetValue !== undefined) {
// case of addEventListener, removeEventListener, setTimeout, setInterval setted in sandbox
return targetValue;
}
Expand Down
22 changes: 22 additions & 0 deletions packages/icestark-sandbox/tests/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,26 @@ describe('sanbox: binding this', () => {
test('bind this to proxy', () => {
sandbox.execScriptInSandbox('expect(window === this).toBe(true);');
});
});

describe('sandbox: falsy values should be trapped.', () => {
const sandbox = new Sandbox({ multiMode: true });

test('Falsy value - 0', () => {
sandbox.execScriptInSandbox('window.a = 0;expect(window.a).toBe(0);');
// eslint-disable-next-line @typescript-eslint/no-explicit-any
expect((window as any).a).toBe(undefined);
});

test('Falsy value - false', () => {
sandbox.execScriptInSandbox('window.b = false;expect(window.b).toBe(false);');
// eslint-disable-next-line @typescript-eslint/no-explicit-any
expect((window as any).a).toBe(undefined);
});

test('Falsy value - void 0', () => {
sandbox.execScriptInSandbox('window.c = void 0;expect(window.c).toBe(undefined);');
// eslint-disable-next-line @typescript-eslint/no-explicit-any
expect((window as any).a).toBe(undefined);
});
});
8 changes: 7 additions & 1 deletion src/util/getLifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ import { AppLifeCycleEnum } from './appLifeCycle';

export function getLifecyleByLibrary () {
const libraryName = getCache('library');
const moduleInfo = window[libraryName] as ModuleLifeCycle;

/**
* if `libraryName` is array, iterate it util a deepest value found.
*/
const moduleInfo = (Array.isArray(libraryName)
? libraryName.reduce((pre, next) => pre[next], window)
: window[libraryName]) as ModuleLifeCycle;

if (moduleInfo && moduleInfo.mount && moduleInfo.unmount) {
const lifecycle = moduleInfo;
Expand Down
37 changes: 37 additions & 0 deletions tests/getLifecycle.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import '@testing-library/jest-dom/extend-expect';

import { setCache } from '../src/util/cache';
import { getLifecyleByLibrary } from '../src/util/getLifecycle';

describe('getLifecycle', () => {
test('getLifecyleByLibrary - string', () => {
// @ts-ignore
window.mockFn = {
mount: jest.fn(),
unmount: jest.fn(),
}
setCache('library', 'mockFn');

expect(getLifecyleByLibrary()).not.toBe(null);
})

test('getLifecyleByLibrary - string[]', () => {
// @ts-ignore
(window.scope = window.scope || {}).mockFn = {
mount: jest.fn(),
unmount: jest.fn(),
}
setCache('library', ['scope', 'mockFn']);

expect(getLifecyleByLibrary()).not.toBe(null);
})

test('getLifecyleByLibrary - undefined', () => {

setCache('library', 'mockData');

expect(getLifecyleByLibrary()).toBe(null);
})
});


0 comments on commit cdb9d6c

Please sign in to comment.