Skip to content

Commit

Permalink
fix: do not include Configstore if not necessary (#270)
Browse files Browse the repository at this point in the history
* fix: do not include Configstore if not necessary

* ci: make sure line endings are preserved
  • Loading branch information
Jason3S authored Nov 8, 2020
1 parent 464f686 commit d8b625f
Show file tree
Hide file tree
Showing 312 changed files with 1,496 additions and 1,366 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# Set the default behavior, in case people don't have core.autocrlf set.
* text=auto
*.txt text eol=lf
*.ts text eol=lf
*.js text eol=lf
7 changes: 5 additions & 2 deletions generator-cspell-dicts/generators/app/templates/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
"<%= fullPackageName %>-link": "./link.js",
"<%= fullPackageName %>-unlink": "./unlink.js"
},
"exports": {
".": "./index.js",
"./cspell-ext.json": "./cspell-ext.json"
},
"scripts": {
"build": "cross-env NODE_OPTIONS=--max_old_space_size=8192 cspell-tools <%= command %> \"<%= srcFile %>\" -o .",
"test": "head -n 100 \"<%= srcFile %>\" | cspell -v -c ./cspell-ext.json \"--local=<%= local %>\" \"--languageId=<%= languageId %>\" stdin",
Expand Down Expand Up @@ -34,8 +38,7 @@
"url": "https://github.com/streetsidesoftware/cspell-dicts/issues"
},
"homepage": "https://github.com/streetsidesoftware/cspell-dicts/blob/master/packages/<%= name %>#readme",
"devDependencies": {
},
"devDependencies": {},
"dependencies": {
"configstore": "^5.0.0"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/ada/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict';

var util = require('./util');
const configLocation = require.resolve('./cspell-ext.json');

function getConfigLocation() {
return util.configLocation;
return configLocation;
}

module.exports = {
Expand Down
2 changes: 1 addition & 1 deletion packages/ada/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

'use strict';

var util = require('./util');
const util = require('./util');

util.install();
4 changes: 4 additions & 0 deletions packages/ada/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
"cspell-dict-ada-link": "./link.js",
"cspell-dict-ada-unlink": "./unlink.js"
},
"exports": {
".": "./index.js",
"./cspell-ext.json": "./cspell-ext.json"
},
"scripts": {
"build": "cspell-tools compile \"ada.txt\" -o .",
"test": "head -n 100 \"ada.txt\" | cspell -v -c ./cspell-ext.json --local=* --languageId=ada stdin",
Expand Down
2 changes: 1 addition & 1 deletion packages/ada/unlink.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

'use strict';

var util = require('./util');
const util = require('./util');

util.uninstall();
34 changes: 16 additions & 18 deletions packages/ada/util.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,40 @@
'use strict';

// Cspell:word configstore
var Configstore = require('configstore');
var Path = require('path');
const Configstore = require('configstore');

var packageName = 'cspell';
var importPath = 'import';
var configLocation = Path.join(__dirname, 'cspell-ext.json');
const packageName = 'cspell';
const importPath = 'import';
const configLocation = require.resolve('./cspell-ext.json');

/**
*
* @param {Configstore} conf
* @returns {string[]}
*/
function getImports(conf) {
var imports = conf.get(importPath);
const imports = conf.get(importPath) || [];

imports = imports || [];
if (typeof imports === 'string') {
imports = [imports];
return [imports];
}

return imports;
}

function install() {
var conf = new Configstore(packageName);
/** @type {string[]|string|undefined} */

var imports = getImports(conf);
const conf = new Configstore(packageName);
const imports = getImports(conf);
if (imports.indexOf(configLocation) < 0) {
imports.push(configLocation);
conf.set(importPath, imports);
}
}

function uninstall() {
var conf = new Configstore(packageName);
/** @type {string[]|string|undefined} */
var imports = getImports(conf);

var index = imports.indexOf(configLocation);

const conf = new Configstore(packageName);
const imports = getImports(conf);
const index = imports.indexOf(configLocation);
if (index >= 0) {
imports.splice(index, 1);
conf.set(importPath, imports);
Expand Down
4 changes: 2 additions & 2 deletions packages/aws/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict';

var util = require('./util');
const configLocation = require.resolve('./cspell-ext.json');

function getConfigLocation() {
return util.configLocation;
return configLocation;
}

module.exports = {
Expand Down
2 changes: 1 addition & 1 deletion packages/aws/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

'use strict';

var util = require('./util');
const util = require('./util');

util.install();
4 changes: 4 additions & 0 deletions packages/aws/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
"cspell-dict-aws-link": "./link.js",
"cspell-dict-aws-unlink": "./unlink.js"
},
"exports": {
".": "./index.js",
"./cspell-ext.json": "./cspell-ext.json"
},
"scripts": {
"build": "cspell-tools compile \"aws.txt\" -o .",
"test": "head -n 100 \"aws.txt\" | cspell -v -c ./cspell-ext.json \"--local=*\" \"--languageId=aws\" stdin",
Expand Down
2 changes: 1 addition & 1 deletion packages/aws/unlink.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

'use strict';

var util = require('./util');
const util = require('./util');

util.uninstall();
34 changes: 16 additions & 18 deletions packages/aws/util.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,40 @@
'use strict';

// Cspell:word configstore
var Configstore = require('configstore');
var Path = require('path');
const Configstore = require('configstore');

var packageName = 'cspell';
var importPath = 'import';
var configLocation = Path.join(__dirname, 'cspell-ext.json');
const packageName = 'cspell';
const importPath = 'import';
const configLocation = require.resolve('./cspell-ext.json');

/**
*
* @param {Configstore} conf
* @returns {string[]}
*/
function getImports(conf) {
var imports = conf.get(importPath);
const imports = conf.get(importPath) || [];

imports = imports || [];
if (typeof imports === 'string') {
imports = [imports];
return [imports];
}

return imports;
}

function install() {
var conf = new Configstore(packageName);
/** @type {string[]|string|undefined} */

var imports = getImports(conf);
const conf = new Configstore(packageName);
const imports = getImports(conf);
if (imports.indexOf(configLocation) < 0) {
imports.push(configLocation);
conf.set(importPath, imports);
}
}

function uninstall() {
var conf = new Configstore(packageName);
/** @type {string[]|string|undefined} */
var imports = getImports(conf);

var index = imports.indexOf(configLocation);

const conf = new Configstore(packageName);
const imports = getImports(conf);
const index = imports.indexOf(configLocation);
if (index >= 0) {
imports.splice(index, 1);
conf.set(importPath, imports);
Expand Down
4 changes: 2 additions & 2 deletions packages/bash/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict';

var util = require('./util');
const configLocation = require.resolve('./cspell-ext.json');

function getConfigLocation() {
return util.configLocation;
return configLocation;
}

module.exports = {
Expand Down
2 changes: 1 addition & 1 deletion packages/bash/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

'use strict';

var util = require('./util');
const util = require('./util');

util.install();
4 changes: 4 additions & 0 deletions packages/bash/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
"cspell-dict-bash-link": "./link.js",
"cspell-dict-bash-unlink": "./unlink.js"
},
"exports": {
".": "./index.js",
"./cspell-ext.json": "./cspell-ext.json"
},
"scripts": {
"build": "cspell-tools compile \"bash-words.txt\" -o .",
"test": "head -n 100 \"bash-words.txt\" | cspell -v -c ./cspell-ext.json \"--local=*\" \"--languageId=shellscript\" stdin",
Expand Down
2 changes: 1 addition & 1 deletion packages/bash/unlink.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

'use strict';

var util = require('./util');
const util = require('./util');

util.uninstall();
34 changes: 16 additions & 18 deletions packages/bash/util.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,40 @@
'use strict';

// Cspell:word configstore
var Configstore = require('configstore');
var Path = require('path');
const Configstore = require('configstore');

var packageName = 'cspell';
var importPath = 'import';
var configLocation = Path.join(__dirname, 'cspell-ext.json');
const packageName = 'cspell';
const importPath = 'import';
const configLocation = require.resolve('./cspell-ext.json');

/**
*
* @param {Configstore} conf
* @returns {string[]}
*/
function getImports(conf) {
var imports = conf.get(importPath);
const imports = conf.get(importPath) || [];

imports = imports || [];
if (typeof imports === 'string') {
imports = [imports];
return [imports];
}

return imports;
}

function install() {
var conf = new Configstore(packageName);
/** @type {string[]|string|undefined} */

var imports = getImports(conf);
const conf = new Configstore(packageName);
const imports = getImports(conf);
if (imports.indexOf(configLocation) < 0) {
imports.push(configLocation);
conf.set(importPath, imports);
}
}

function uninstall() {
var conf = new Configstore(packageName);
/** @type {string[]|string|undefined} */
var imports = getImports(conf);

var index = imports.indexOf(configLocation);

const conf = new Configstore(packageName);
const imports = getImports(conf);
const index = imports.indexOf(configLocation);
if (index >= 0) {
imports.splice(index, 1);
conf.set(importPath, imports);
Expand Down
4 changes: 2 additions & 2 deletions packages/bg_BG/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict';

var util = require('./util');
const configLocation = require.resolve('./cspell-ext.json');

function getConfigLocation() {
return util.configLocation;
return configLocation;
}

module.exports = {
Expand Down
2 changes: 1 addition & 1 deletion packages/bg_BG/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

'use strict';

var util = require('./util');
const util = require('./util');

util.install();
4 changes: 4 additions & 0 deletions packages/bg_BG/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
"cspell-dict-bg-bg-link": "./link.js",
"cspell-dict-bg-bg-unlink": "./unlink.js"
},
"exports": {
".": "./index.js",
"./cspell-ext.json": "./cspell-ext.json"
},
"scripts": {
"build": "cspell-tools compile-trie \"bg_BG.dic\" -o .",
"test": "hunspell-reader words -n 1000 \"bg_BG.dic\" | cspell -v -c ./cspell-ext.json \"--local=bg\" \"--languageId=*\" stdin",
Expand Down
2 changes: 1 addition & 1 deletion packages/bg_BG/unlink.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

'use strict';

var util = require('./util');
const util = require('./util');

util.uninstall();
Loading

0 comments on commit d8b625f

Please sign in to comment.