This repository has been archived by the owner on Mar 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathindex.coffee
64 lines (55 loc) · 1.95 KB
/
index.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
'use strict'
path = require 'path'
pp = require 'preprocess'
loaderUtils = require 'loader-utils'
# Object.assign polyfill
# https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign#Polyfill
if typeof Object.assign != 'function'
# Must be writable: true, enumerable: false, configurable: true
Object.defineProperty Object, 'assign',
value: (target, varArgs) ->
# .length of function is 2
'use strict'
if target == null
# TypeError if undefined or null
throw new TypeError('Cannot convert undefined or null to object')
to = Object(target)
index = 1
while index < arguments.length
nextSource = arguments[index]
if nextSource != null
# Skip over if undefined or null
for nextKey of nextSource
# Avoid bugs when hasOwnProperty is shadowed
if Object::hasOwnProperty.call(nextSource, nextKey)
to[nextKey] = nextSource[nextKey]
index++
to
writable: true
configurable: true
# ---
# generated by js2coffee 2.2.0
module.exports = (source) ->
@cacheable?()
# parse file extension
[..., extension] = path.extname(@resourcePath or '').split('.')
# prepare preprocess options
options =
#fileNotFoundSilentFail: false
#srcEol: os.EOL
srcDir: @context
type: extension
# parse and init context from query
query = loaderUtils.getOptions(this) || {}
# get possible user-specific preprocess options from query
if typeof query.ppOptions is 'object'
options = Object.assign options, query.ppOptions
delete query.ppOptions
# add .cjsx alias
options.type = 'coffee' if /cjsx/i.test options.type
# prepare context variables
context = Object.assign {}, process.env, query
context.NODE_ENV = context.NODE_ENV or 'development'
# pp
processed = pp.preprocess source, context, options
@callback null, processed