terraform 1.12.0 → 1.20.2

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.
@@ -15,7 +15,7 @@ var TerraformError = exports.TerraformError = require("../error").TerraformError
15
15
  var processors = exports.processors = {
16
16
  "html": ["jade", "ejs", "md"],
17
17
  "css" : ["styl", "less", "scss", "sass"],
18
- "js" : ["coffee"]
18
+ "js" : ["jsx", "cjs", "coffee"]
19
19
  }
20
20
 
21
21
 
@@ -92,6 +92,36 @@ var buildPriorityList = exports.buildPriorityList = function(filePath){
92
92
  }
93
93
 
94
94
 
95
+ var buildPartialPriorityList = exports.buildPartialPriorityList = function(filePath){
96
+
97
+ var list = []
98
+ var ext = path.extname(filePath).replace(/^\./, '')
99
+ var processor = processors[ext]
100
+
101
+ var addPartialPaths = function(proList){
102
+ // foo.html => foo.jade
103
+ proList.forEach(function(p){
104
+ var regexp = new RegExp(ext + '$')
105
+ list.push(filePath.replace(regexp, p))
106
+ })
107
+
108
+ // foo.html => foo.html.jade
109
+ proList.forEach(function(p){
110
+ list.push(filePath + '.' + p)
111
+ })
112
+ }
113
+
114
+ addPartialPaths(processors["html"])
115
+ addPartialPaths(processors["js"])
116
+ addPartialPaths(processors["css"])
117
+
118
+ // remove leading and trailing slashes
119
+ var list = list.map(function(item){ return item.replace(/^\/|^\\|\/$/g, '') })
120
+
121
+ return list
122
+ }
123
+
124
+
95
125
  /**
96
126
  * Find First File
97
127
  *
@@ -446,7 +476,7 @@ exports.shouldIgnore = function(filePath){
446
476
 
447
477
  // test for starting underscore, .git, .gitignore
448
478
  var map = arr.map(function(item){
449
- return item[0] === "_" || item.indexOf(".git") === 0
479
+ return item[0] === "_" || item.indexOf("%5f") === 0 || item.indexOf(".git") === 0
450
480
  })
451
481
 
452
482
  // return if any item starts with underscore
@@ -8,6 +8,7 @@ var helpers = require('../helpers')
8
8
  * same as doing...
9
9
  *
10
10
  * var processors = {
11
+ * "cjs" : require("./processors/cjs")
11
12
  * "coffee" : require("./processors/coffee")
12
13
  * }
13
14
  *
@@ -18,88 +19,46 @@ helpers.processors["js"].forEach(function(sourceType){
18
19
  processors[sourceType] = require("./processors/" + sourceType)
19
20
  })
20
21
 
21
- module.exports = function(root, filePath, callback){
22
-
23
- var srcPath = path.resolve(root, filePath)
24
- var ext = path.extname(srcPath).replace(/^\./, '')
25
- var minifyOpts = {
26
- compress: false,
27
- mangle: false
22
+ module.exports = function(rootPath, filePath, options, callback){
23
+
24
+ if(!callback) {
25
+ callback = options
26
+ options = {}
28
27
  }
29
28
 
30
- fs.readFile(srcPath, function(err, data){
31
-
32
- /**
33
- * File not Found
34
- */
35
-
36
- if(err && err.code === 'ENOENT') return callback(null, null)
37
-
38
- /**
39
- * Read File Error
40
- */
41
-
42
- if(err) return callback(err)
29
+ var ext = path.extname(filePath).replace(/^\./, '')
30
+ return processors[ext].compile(rootPath, filePath, options, callback)
43
31
 
44
- /**
45
- * Lookup Directories
46
- */
32
+ // fs.readFile(srcPath, function(err, data){
47
33
 
48
- var render = function(ext, data, cb) {
49
- processors[ext].compile(srcPath, data, function(err, js) {
50
- if (err) return cb(err)
34
+ // /**
35
+ // * File not Found
36
+ // */
51
37
 
52
- /**
53
- * Consistently minify
54
- */
55
- cb(null, js, minifyOpts)
56
- })
57
- }
38
+ // if(err && err.code === 'ENOENT') return callback(null, null)
58
39
 
59
- render(ext, data, callback)
40
+ // /**
41
+ // * Read File Error
42
+ // */
60
43
 
61
- // if(helpers.needsBrowserify(data.toString())) {
62
- // var post = '', success = true
44
+ // if(err) return callback(err)
63
45
 
64
- // var exceptionHandler = function(err) {
65
- // success = false
66
- // console.log(err.message)
67
- // render(ext, data, callback)
68
- // }
46
+ // /**
47
+ // * Lookup Directories
48
+ // */
69
49
 
70
- // process.once('uncaughtException', exceptionHandler)
71
- // browserify(srcPath, {extensions: extensions}).transform(function(file) {
72
- // var result = ''
73
- // return through(write, end)
50
+ // var render = function(ext, data, cb) {
51
+ // processors[ext].compile(srcPath, data, function(err, js) {
52
+ // if (err) return cb(err)
53
+ // /**
54
+ // * Consistently minify
55
+ // */
56
+ // cb(null, js)
57
+ // })
58
+ // }
74
59
 
75
- // function write(buf) {
76
- // result += buf
77
- // }
78
- // function end() {
79
- // if(success) {
80
- // var that = this
81
- // render(path.extname(file).replace(/^\./, '').toLowerCase(), result, function(err, data) {
82
- // that.queue(data)
83
- // that.queue(null)
84
- // })
85
- // }
86
- // }
87
- // }).on('error', exceptionHandler).bundle()
88
- // .on('data', function(buf) {
89
- // if (success) {
90
- // post += buf
91
- // }
92
- // }).on('end', function() {
93
- // if (success) {
94
- // process.removeListener('uncaughtException', exceptionHandler)
95
- // callback(null, minify.js(post, minifyOpts))
96
- // }
97
- // })
98
- // }
99
- // else {
100
- // render(ext, data, callback)
101
- // }
60
+ // render(ext, data, callback)
102
61
 
103
- })
62
+ // })
104
63
 
105
64
  }
@@ -0,0 +1,34 @@
1
+
2
+ var esbuild = require("esbuild")
3
+ var TerraformError = require("../../error").TerraformError
4
+ var path = require("path")
5
+
6
+ exports.compile = function(rootPath, filePath, options, callback){
7
+ var srcFullPath = path.resolve(rootPath, filePath)
8
+ // var publicPath = filePath.replace(/\.js\.cjs$/, ".js").replace(/\.cjs$/, ".js")
9
+ try{
10
+ var errors = null
11
+ var results = esbuild.buildSync({
12
+ entryPoints: [srcFullPath],
13
+ absWorkingDir: rootPath,
14
+ //outfile: publicPath,
15
+ bundle: true,
16
+ write: false,
17
+ minify: options.hasOwnProperty("minify") ? options.minify : false,
18
+ plugins: [],
19
+ })
20
+ var script = results.outputFiles[0]["text"]
21
+ }catch(e){
22
+ var errorObject = e.errors[0]
23
+ var errors = errorObject
24
+ errors.source = "JSX"
25
+ errors.dest = "JavaScript"
26
+ errors.filename = filePath
27
+ errors.stack = errorObject["text"]
28
+ errors.lineno = parseInt(errorObject["location"]["line"])
29
+ var script = null
30
+ var error = new TerraformError(errors)
31
+ }finally{
32
+ return callback(error, script)
33
+ }
34
+ }
@@ -1,6 +1,10 @@
1
1
  var TerraformError = require("../../error").TerraformError
2
+ var fs = require("fs")
3
+ var path = require("path")
2
4
 
3
- exports.compile = function(filePath, fileContents, callback){
5
+ exports.compile = function(rootPath, filePath, options, callback){
6
+
7
+ var srcFullPath = path.resolve(rootPath, filePath)
4
8
 
5
9
  try{
6
10
  var cs = require("coffeescript")
@@ -21,6 +25,7 @@ exports.compile = function(filePath, fileContents, callback){
21
25
  }
22
26
 
23
27
  try{
28
+ var fileContents = fs.readFileSync(srcFullPath)
24
29
  var errors = null
25
30
  var script = cs.compile(fileContents.toString(), { bare: true })
26
31
  }catch(e){
@@ -0,0 +1,35 @@
1
+
2
+ var TerraformError = require("../../error").TerraformError
3
+ var path = require("path")
4
+ var esbuild = require("esbuild")
5
+
6
+ exports.compile = function(rootPath, filePath, options, callback){
7
+ var srcFullPath = path.resolve(rootPath, filePath)
8
+ // var publicPath = filePath.replace(/\.js\.cjs$/, ".js").replace(/\.cjs$/, ".js")
9
+ try{
10
+ var errors = null
11
+ var results = esbuild.buildSync({
12
+ entryPoints: [srcFullPath],
13
+ absWorkingDir: rootPath,
14
+ //outfile: publicPath,
15
+ bundle: true,
16
+ write: false,
17
+ minify: options.hasOwnProperty("minify") ? options.minify : false,
18
+ plugins: [],
19
+ //inject: [__dirname + "/react-shim.js"],
20
+ })
21
+ var script = results.outputFiles[0]["text"]
22
+ }catch(e){
23
+ var errorObject = e.errors[0]
24
+ var errors = errorObject
25
+ errors.source = "JSX"
26
+ errors.dest = "JavaScript"
27
+ errors.filename = filePath
28
+ errors.stack = errorObject["text"]
29
+ errors.lineno = parseInt(errorObject["location"]["line"])
30
+ var script = null
31
+ var error = new TerraformError(errors)
32
+ }finally{
33
+ return callback(error, script)
34
+ }
35
+ }
@@ -0,0 +1,2 @@
1
+ import * as React from 'react'
2
+ export { React }
@@ -19,44 +19,52 @@ helpers.processors["css"].forEach(function(sourceType){
19
19
  processors[sourceType] = require("./processors/" + sourceType)
20
20
  })
21
21
 
22
- module.exports = function(root, filePath, callback){
22
+ module.exports = function(rootPath, filePath, options, callback){
23
23
 
24
- var srcPath = path.resolve(root, filePath)
25
- var ext = path.extname(srcPath).replace(/^\./, '')
24
+ if(!callback) {
25
+ callback = options
26
+ options = {}
27
+ }
26
28
 
29
+ var ext = path.extname(filePath).replace(/^\./, '')
30
+ return processors[ext].compile(rootPath, filePath, options, callback)
27
31
 
28
- fs.readFile(srcPath, function(err, data){
32
+ // var srcPath = path.resolve(root, filePath)
33
+ // var ext = path.extname(srcPath).replace(/^\./, '')
29
34
 
30
- /**
31
- * File not Found
32
- */
33
35
 
34
- if(err && err.code === 'ENOENT') return callback(null, null)
36
+ // fs.readFile(srcPath, function(err, data){
35
37
 
36
- /**
37
- * Read File Error
38
- */
38
+ // /**
39
+ // * File not Found
40
+ // */
39
41
 
40
- if(err) return callback(err)
42
+ // if(err && err.code === 'ENOENT') return callback(null, null)
41
43
 
44
+ // /**
45
+ // * Read File Error
46
+ // */
42
47
 
43
- /**
44
- * Lookup Directories
45
- */
48
+ // if(err) return callback(err)
46
49
 
47
- var dirs = [
48
- path.dirname(srcPath),
49
- path.dirname(path.resolve(root))
50
- ]
51
50
 
52
- /**
53
- * Lookup Directories
54
- */
55
- var render = processors[ext].compile(srcPath, dirs, data, function(err, css, sourcemap) {
56
- if (err) return callback(err);
57
- return callback(null, css.toString(), sourcemap)
58
- })
51
+ // *
52
+ // * Lookup Directories
53
+
59
54
 
60
- })
55
+ // var dirs = [
56
+ // path.dirname(srcPath),
57
+ // path.dirname(path.resolve(root))
58
+ // ]
59
+
60
+ // /**
61
+ // * Lookup Directories
62
+ // */
63
+ // var render = processors[ext].compile(srcPath, dirs, data, function(err, css, sourcemap) {
64
+ // if (err) return callback(err);
65
+ // return callback(null, css.toString(), sourcemap)
66
+ // })
67
+
68
+ // })
61
69
 
62
70
  }
@@ -1,6 +1,8 @@
1
1
  var TerraformError = require("../../error").TerraformError
2
+ var path = require("path")
3
+ var fs = require("fs")
2
4
 
3
- exports.compile = function(filePath, dirs, fileContents, callback){
5
+ exports.compile = function(rootPath, filePath, options, callback){
4
6
 
5
7
  // there must be a better way to do this...
6
8
  try{
@@ -21,6 +23,19 @@ exports.compile = function(filePath, dirs, fileContents, callback){
21
23
  }
22
24
  }
23
25
 
26
+ var srcFullPath = path.resolve(rootPath, filePath)
27
+
28
+ try{
29
+ var fileContents = fs.readFileSync(srcFullPath)
30
+ }catch(e){
31
+ return callback(null, null)
32
+ }
33
+
34
+ var dirs = [
35
+ path.dirname(srcFullPath),
36
+ path.dirname(path.resolve(rootPath))
37
+ ]
38
+
24
39
  var formatError = function(e){
25
40
  return new TerraformError({
26
41
  source: "Less",
@@ -33,6 +48,7 @@ exports.compile = function(filePath, dirs, fileContents, callback){
33
48
  })
34
49
  }
35
50
 
51
+
36
52
  less.render(fileContents.toString(), {
37
53
  paths: dirs, // Specify search paths for @import directives
38
54
  filename: filePath, // Specify a filename, for better error messages
@@ -41,7 +57,7 @@ exports.compile = function(filePath, dirs, fileContents, callback){
41
57
  }, function(e, css){
42
58
  if (e) return callback(formatError(e))
43
59
  var map = css.map || ""
44
- return callback(null, css.css, map.toString())
60
+ return callback(null, css.css.toString(), map.toString())
45
61
  })
46
62
  }
47
63
 
@@ -1,9 +1,25 @@
1
1
  var sass = require("sass")
2
2
  var TerraformError = require("../../error").TerraformError
3
+ var path = require("path")
4
+ var fs = require("fs")
5
+
6
+ exports.compile = function(rootPath, filePath, options, callback){
7
+
8
+ var srcFullPath = path.resolve(rootPath, filePath)
9
+
10
+ try{
11
+ var fileContents = fs.readFileSync(srcFullPath)
12
+ }catch(e){
13
+ return callback(null, null)
14
+ }
15
+
16
+ var dirs = [
17
+ path.dirname(srcFullPath),
18
+ path.dirname(path.resolve(rootPath))
19
+ ]
3
20
 
4
- exports.compile = function(filePath, dirs, fileContents, callback){
5
21
  sass.render({
6
- file: filePath,
22
+ file: srcFullPath,
7
23
  includePaths: dirs,
8
24
  outputStyle: 'compressed',
9
25
  sourceMap: true,
@@ -23,8 +39,7 @@ exports.compile = function(filePath, dirs, fileContents, callback){
23
39
  stack: fileContents.toString()
24
40
  })
25
41
  return callback(error)
26
- }
27
-
28
- callback(null, css.css, css.map.toString())
42
+ }
43
+ callback(null, css.css.toString(), css.map.toString())
29
44
  });
30
45
  }
@@ -1,9 +1,25 @@
1
1
  var scss = require("sass")
2
2
  var TerraformError = require("../../error").TerraformError
3
+ var path = require("path")
4
+ var fs = require("fs")
5
+
6
+ exports.compile = function(rootPath, filePath, options, callback){
7
+
8
+ var srcFullPath = path.resolve(rootPath, filePath)
9
+
10
+ try{
11
+ var fileContents = fs.readFileSync(srcFullPath)
12
+ }catch(e){
13
+ return callback(null, null)
14
+ }
15
+
16
+ var dirs = [
17
+ path.dirname(srcFullPath),
18
+ path.dirname(path.resolve(rootPath))
19
+ ]
3
20
 
4
- exports.compile = function(filePath, dirs, fileContents, callback){
5
21
  scss.render({
6
- file: filePath,
22
+ file: srcFullPath,
7
23
  includePaths: dirs,
8
24
  outputStyle: 'compressed',
9
25
  sourceMap: true,
@@ -24,6 +40,6 @@ exports.compile = function(filePath, dirs, fileContents, callback){
24
40
  })
25
41
  return callback(error)
26
42
  }
27
- callback(null, css.css, css.map.toString())
43
+ callback(null, css.css.toString(), css.map.toString())
28
44
  });
29
45
  }
@@ -1,7 +1,21 @@
1
1
  var TerraformError = require("../../error").TerraformError
2
+ var path = require("path")
3
+ var fs = require("fs")
2
4
 
3
- exports.compile = function(filePath, dirs, fileContents, callback){
5
+ exports.compile = function(rootPath, filePath, options, callback){
4
6
 
7
+ var srcFullPath = path.resolve(rootPath, filePath)
8
+
9
+ try{
10
+ var fileContents = fs.readFileSync(srcFullPath)
11
+ }catch(e){
12
+ return callback(null, null)
13
+ }
14
+
15
+ var dirs = [
16
+ path.dirname(srcFullPath),
17
+ path.dirname(path.resolve(rootPath))
18
+ ]
5
19
 
6
20
  // there must be a better way to do this...
7
21
  try{
@@ -23,7 +37,7 @@ exports.compile = function(filePath, dirs, fileContents, callback){
23
37
  }
24
38
 
25
39
  var style = stylus(fileContents.toString())
26
- style.set('filename', filePath)
40
+ style.set('filename', srcFullPath)
27
41
  style.set('paths', dirs)
28
42
  style.set('compress', true)
29
43
  style.set('include css', true)
@@ -143,6 +143,7 @@ var scope = module.exports = function(projectPath, parentLocals){
143
143
  * note - layouts get the same scope as the partial
144
144
  *
145
145
  */
146
+
146
147
  var tmpl = processors[ext](fileContents, { filename: filePath, basedir: projectPath })
147
148
 
148
149
  try{
@@ -0,0 +1,27 @@
1
+ var ReactDOMServer = require('react-dom/server')
2
+ var TerraformError = require("../../error").TerraformError
3
+
4
+ module.exports = function(fileContents, options){
5
+
6
+ return {
7
+ compile: function(){
8
+ return ejs.compile(fileContents.toString(), Object.assign(options, { rmWhitespace: true }))
9
+ },
10
+
11
+ parseError: function(error){
12
+ var arr = error.message.split("\n")
13
+ var path_arr = arr[0].split(":")
14
+
15
+ error.lineno = parseInt(error.lineno || path_arr[path_arr.length -1] || -1)
16
+ error.message = arr[arr.length - 1]
17
+ error.name = error.name
18
+ error.source = "EJS"
19
+ error.dest = "HTML"
20
+ error.filename = error.path || options.filename
21
+ error.stack = fileContents.toString()
22
+
23
+ return new TerraformError(error)
24
+ }
25
+ }
26
+
27
+ }
package/lib/terraform.js CHANGED
@@ -1,4 +1,4 @@
1
- var fs = require('fs')
1
+
2
2
  var path = require('path')
3
3
  var stylesheet = require('./stylesheet')
4
4
  var template = require('./template')
@@ -54,7 +54,6 @@ exports.root = function(root, globals){
54
54
  */
55
55
 
56
56
  render: function(filePath, locals, callback){
57
-
58
57
  // get rid of leading slash (windows)
59
58
  filePath = filePath.replace(/^\\/g, '')
60
59
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "terraform",
3
- "version": "1.12.0",
3
+ "version": "1.20.2",
4
4
  "description": "pre-processor engine that powers the harp web server",
5
5
  "repository": {
6
6
  "type": "git",
@@ -8,7 +8,8 @@
8
8
  },
9
9
  "main": "./lib/terraform",
10
10
  "scripts": {
11
- "test": "mocha --reporter spec"
11
+ "test": "mocha --reporter spec",
12
+ "test:css": "mocha test/stylesheets --reporter spec"
12
13
  },
13
14
  "author": "Brock Whitten <brock@chloi.io>",
14
15
  "contributors": [
@@ -41,9 +42,11 @@
41
42
  ],
42
43
  "license": "MIT",
43
44
  "dependencies": {
44
- "ejs": "2.5.7",
45
+ "ejs": "^3.1.6",
46
+ "esbuild": "^0.12.1",
45
47
  "lru-cache": "4.1.1",
46
- "marked": "^0.7.0",
48
+ "marked": "^4.0.10",
49
+ "react": "^17.0.2",
47
50
  "sass": "^1.29.0",
48
51
  "through": "2.3.8"
49
52
  },
@@ -52,6 +55,6 @@
52
55
  "less": "^4.1.1",
53
56
  "mocha": "^8.4.0",
54
57
  "should": "3.3.2",
55
- "stylus": "0.54.8"
58
+ "stylus": "^0.56.0"
56
59
  }
57
60
  }