mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 04:10:40 -07:00
fix: support for NodeJS 15, fixes #732
This commit is contained in:
@@ -15,6 +15,9 @@ jobs:
|
||||
- os: ubuntu-latest
|
||||
timezone: Etc/GMT
|
||||
node-version: 16
|
||||
- os: ubuntu-latest
|
||||
timezone: Asia/Shanghai
|
||||
node-version: 15
|
||||
- os: ubuntu-latest
|
||||
timezone: Asia/Shanghai
|
||||
node-version: 14
|
||||
|
||||
@@ -50,10 +50,6 @@ const browserStream = {
|
||||
delimiters: ['', ''],
|
||||
'./streamed-emitter': '../build/streamed-emitter-browser'
|
||||
}
|
||||
const browserPerf = {
|
||||
include: ['./src/context/context.ts', './src/render/render.ts'],
|
||||
'node:perf_hooks': '../build/perf_hooks-browser'
|
||||
}
|
||||
const esmRequire = {
|
||||
include: './src/fs/node.ts',
|
||||
delimiters: ['', ''],
|
||||
@@ -99,7 +95,6 @@ const browserEsm = {
|
||||
versionInjection,
|
||||
replace(browserFS),
|
||||
replace(browserStream),
|
||||
replace(browserPerf),
|
||||
typescript(tsconfig('es6'))
|
||||
],
|
||||
treeshake,
|
||||
@@ -118,7 +113,6 @@ const browserUmd = {
|
||||
versionInjection,
|
||||
replace(browserFS),
|
||||
replace(browserStream),
|
||||
replace(browserPerf),
|
||||
typescript(tsconfig('es5'))
|
||||
],
|
||||
treeshake,
|
||||
@@ -137,7 +131,6 @@ const browserMin = {
|
||||
versionInjection,
|
||||
replace(browserFS),
|
||||
replace(browserStream),
|
||||
replace(browserPerf),
|
||||
typescript(tsconfig('es5')),
|
||||
uglify()
|
||||
],
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
const polyfill = {
|
||||
now: () => Date.now()
|
||||
}
|
||||
|
||||
export const performance = typeof window === 'object' && window.performance || polyfill
|
||||
@@ -1,4 +1,4 @@
|
||||
import { performance } from 'node:perf_hooks'
|
||||
import { getPerformance } from '../util/performance'
|
||||
import { Drop } from '../drop/drop'
|
||||
import { __assign } from 'tslib'
|
||||
import { NormalizedFullOptions, defaultOptions, RenderOptions } from '../liquid-options'
|
||||
@@ -44,7 +44,7 @@ export class Context {
|
||||
this.strictVariables = renderOptions.strictVariables ?? this.opts.strictVariables
|
||||
this.ownPropertyOnly = renderOptions.ownPropertyOnly ?? opts.ownPropertyOnly
|
||||
this.memoryLimit = memoryLimit ?? new Limiter('memory alloc', renderOptions.memoryLimit ?? opts.memoryLimit)
|
||||
this.renderLimit = renderLimit ?? new Limiter('template render', performance.now() + (renderOptions.renderLimit ?? opts.renderLimit))
|
||||
this.renderLimit = renderLimit ?? new Limiter('template render', getPerformance().now() + (renderOptions.renderLimit ?? opts.renderLimit))
|
||||
}
|
||||
public getRegister (key: string) {
|
||||
return (this.registers[key] = this.registers[key] || {})
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { performance } from 'node:perf_hooks'
|
||||
import { getPerformance } from '../util/performance'
|
||||
import { toPromise, RenderError, LiquidErrors, LiquidError } from '../util'
|
||||
import { Context } from '../context'
|
||||
import { Template } from '../template'
|
||||
@@ -17,7 +17,7 @@ export class Render {
|
||||
}
|
||||
const errors = []
|
||||
for (const tpl of templates) {
|
||||
ctx.renderLimit.check(performance.now())
|
||||
ctx.renderLimit.check(getPerformance().now())
|
||||
try {
|
||||
// if tpl.render supports emitter, it'll return empty `html`
|
||||
const html = yield tpl.render(ctx, emitter)
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import { getPerformance } from './performance'
|
||||
|
||||
describe('performance', () => {
|
||||
let globalPerformance: Performance
|
||||
beforeEach(() => {
|
||||
globalPerformance = global.performance
|
||||
})
|
||||
afterEach(() => {
|
||||
global.performance = globalPerformance
|
||||
delete (global as any).window
|
||||
})
|
||||
it('should use global.performance if exist', () => {
|
||||
const performance = {} as any as Performance
|
||||
global.performance = performance
|
||||
expect(getPerformance()).toEqual(performance)
|
||||
})
|
||||
it('should use window.performance if exist', () => {
|
||||
const performance = {} as any as Performance
|
||||
delete (global as any).performance
|
||||
global.window = { performance } as any
|
||||
expect(getPerformance()).toEqual(performance)
|
||||
})
|
||||
it('should use polyfill if no window/global.performance', () => {
|
||||
delete (global as any).performance
|
||||
const now = getPerformance().now()
|
||||
expect(Number.isInteger(now)).toBeTruthy()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,13 @@
|
||||
interface LiquidPerformance {
|
||||
now: () => number
|
||||
}
|
||||
|
||||
const polyfill: LiquidPerformance = {
|
||||
now: () => Date.now()
|
||||
}
|
||||
|
||||
export function getPerformance (): LiquidPerformance {
|
||||
return (typeof global === 'object' && global.performance) ||
|
||||
(typeof window === 'object' && window.performance) ||
|
||||
polyfill
|
||||
}
|
||||
Reference in New Issue
Block a user